﻿///  Copyright (c) 2009 Ray Liang (http://www.dotnetage.com)
///  Dual licensed under the MIT and GPL licenses:
///  http://www.opensource.org/licenses/mit-license.php
///  http://www.gnu.org/licenses/gpl.html
///  Current Version 1.0.3
///  Released :2010-10-31
(function($){$.widget("ui.actionLink",{options:{icon:"ui-icon-extlink",text:"button",cssClass:"ui-state-default ui-corner-all",hoverClass:"ui-state-hover",click:null},_create:function(){var self=this,opts=this.options,_link=this.element;_link.text(opts.text);if(opts.cssClass)
_link.addClass(opts.cssClass);_link.css({"padding":"5px 5px 5px 8px","margin":"2px","display":"inline-block","text-decoration":"none","cursor":"pointer","border":"none","background":"none"});if(opts.click){_link.attr("href","javascript:void(0);").bind("click",opts.click);}
if(opts.hoverClass){_link.hover(function(){$(this).addClass(opts.hoverClass);},function(){$(this).removeClass(opts.hoverClass);});}
if(opts.icon){var _linkicon=$("<span class='"+opts.icon+"'></span>");_linkicon.css({"float":"left","margin-right":"0.3em"});_link.prepend(_linkicon);}},widget:function(){return this.element;},destory:function(){$.Widget.prototype.destroy.call(this);}});$.widget("ui.checkbox",{options:{value:false,text:"",checkboxClass:"ui-icon",selectedClass:"ui-icon-check",unselectedClass:"ui-icon-radio-on",changed:null},_create:function(){var self=this,opts=this.options,$el=this.element,eventPrefix=this.widgetEventPrefix;$el.disableSelection();$el.wrap("<div class='ui-checkbox' style='display:inline;'></div>");var _c=this._container=$el.parent(),_ico=$("<span class='ui-checkbox-ico'></span>").appendTo(_c).css({"float":"left"}).addClass(opts.unselectedClass),_txt=$("<span></span>").appendTo(_c).css({"float":"left","cursor":"default"}).addClass("ui-checkbox-text").text(opts.text);_c.attr("tabIndex","0");this._icon=_ico;this._text=_txt;if(opts.changed)
$el.bind(eventPrefix+"changed",opts.changed);if(opts.checkboxClass)
_ico.addClass(opts.checkboxClass);self._setValue();_ico.bind("click",function(){opts.value=!opts.value;self._setValue();$el.trigger(eventPrefix+"changed",opts.value);});_txt.bind("click",function(){_ico.click();});},clear:function(){var self=this,opts=this.options;opts.value=false;},_setValue:function(){var self=this,opts=this.options;if(opts.value){self._icon.removeClass(opts.unselectedClass);self._icon.addClass(opts.selectedClass);}
else{self._icon.removeClass(opts.selectedClass);self._icon.addClass(opts.unselectedClass);}
$(self.element).val(opts.value);},destroy:function(){this._icon.unbind();this._text.unbind();$.Widget.prototype.destroy.call(this);}});$.widget("ui.dropdown",{options:{autosize:false,itemClass:"ui-dropdown-item ui-state-default",hoverClass:"ui-state-hover",highlightClass:"ui-state-highlight",selectedClass:"ui-state-active",appendText:"",height:23,width:150,minHeight:200,iconClass:"ui-icon ui-icon-triangle-1-s",textField:":first",valueField:">input[type='hidden']",selectWholeItem:false,container:">ul",items:"li",selectedIndex:-1,selectedValue:null,defaultText:"Please select an item",selectedChanged:null,beforeOpen:null,afterOpen:null,beforeClose:null,afterClose:null,resizable:false,editable:false,value:null},_create:function(){var self=this,opts=this.options,_el=this.element,_container=null;if(opts.beforeOpen)
_el.bind("beforeDropdownOpen",opts.beforeOpen);if(opts.afterOpen)
_el.bind("afterDropdownOpen",opts.afterOpen);if(opts.beforeClose)
_el.bind("beforeDropdownClose",opts.beforeClose);if(opts.afterClose)
_el.bind("afterDropdownClose",opts.afterClose);if(opts.selectedChanged)
_el.bind("selectedChanged",opts.selectedChanged);if(opts.autosize!=true)
_el.width(opts.width);_el.height(opts.height);if(!_el.hasClass("ui-dropdown"))
_el.addClass("ui-dropdown");_el.addClass("ui-state-default");_el.addClass("ui-corner-all");if(opts.editable){var _editableText=$("<input type='text' name='"+_el.attr("id")+"' />").appendTo(_el).css({"border":"none","background":"none","display":"inline-block","margin":"1px","padding-right":"16px","color":_el.css("color")});if($.browser.msie)
_editableText.width(_el.width()-16);if(opts.value)
_editableText.val(opts.value);_editableText.bind("change",function(){opts.value=_editableText.val();});}else{var _hideValue=$(">input[type='hidden']",_el);if(_hideValue.length==0)
_el.append($("<input type='hidden' name='"+_el.attr("id")+"' />"));_hideValue.bind("change",function(){opts.value=_hideValue.val();});}
var _staticTxt=$("<div class='ui-dropdown-text'></div>");_staticTxt.text(opts.defaultText);var _icon=$("<span class='ui-dropdown-icon'></span>");if(opts.iconClass)
_icon.addClass(opts.iconClass);if(opts.container){if(opts.container.jquery)
_container=opts.container;else
_container=$(opts.container,_el);if(_container.length>0){_container.addClass("ui-dropdown-container");if($.fn.bgiframe)
_container.bgiframe();_container.addClass("ui-helper-reset ui-helper-hidden ui-widget-content");if(opts.resizable){if($.fn.resizable){_container.css({"overflow":"hidden"});_container.resizable({minHeight:_container.height(),minWidth:_el.width()});}}}}
if(!opts.editable)
_el.prepend(_staticTxt);_el.append(_icon);if(opts.items){var _items=$(opts.items,_el);if(_items.length>0){self.items=_items;_items.disableSelection();_items.addClass(opts.itemClass);_items.hover(function(){$(this).addClass(opts.hoverClass);},function(){$(this).removeClass(opts.hoverClass);});_items.click(function(){_items.removeClass(opts.selectedClass);self._setSelect(this);self.close();});if(opts.selectedIndex>-1){if(_items.get(opts.selectedIndex)){self._setSelect(_items.get(opts.selectedIndex),true);}}
else{if(opts.selectedValue){self.select(opts.selectedValue,true);}}}}
_el.hover(function(){$(this).addClass(opts.highlightClass);},function(){$(this).removeClass(opts.highlightClass);});_el.toggle(function(){self.open();},function(evt){var t=$(evt.target);if(t.hasClass("ui-dropdown")||t.hasClass("ui-dropdown-text")||t.hasClass("ui-dropdown-icon"))
self.close();});},select:function(v,notfire){var self=this,opts=this.options;if(v){if(opts.valueField){if(self.items){self.items.each(function(i,n){var vf=$(opts.valueField,n);if(vf.length>0){if((vf.val()==v)||(vf.text()==v)){self._setSelect(n,notfire);return;}}});}}}},_setSelect:function(_item,notfire){var self=this,opts=this.options;var _staticTxt=$(".ui-dropdown-text",self.element);var _dropdownValue=$(">input[type='hidden']",self.element);if(opts.editable)
_dropdownValue=$(">input[type='text']",self.element);if(opts.items){var _items=$(opts.items,this.element);if(_items.length>0)
opts.selectedIndex=_items.index($(_item));}
if(!$(_item).hasClass(opts.selectedClass))
$(_item).addClass(opts.selectedClass);var sameAsText=false;if(opts.valueField){if(_dropdownValue.length>0){var _vi=$(opts.valueField,_item);if(_vi.length>0){_dropdownValue.val(_vi.val());opts.selectedValue=_vi.val();}
else sameAsText=true;}else sameAsText=true;}
else
sameAsText=true;var _selectedText="";if(opts.selectWholeItem){if(!opts.editable)
_staticTxt.html($(_item).html());}
else{var _dispTxt="";if((opts.textField!="")&&(opts.textField!=undefined)){var _tf=$(opts.textField,_item);if(_tf.length>0)
_selectedText=_tf.text();else
_selectedText=$(_item).text();if((opts.appendText!=undefined)&&(opts.appendText!=""))
_dispTxt=opts.appendText+":"+_selectedText;else
_dispTxt=_selectedText;}
if(!opts.editable){if(_dispTxt!="")
_staticTxt.text(_dispTxt);else
_staticTxt.html($(_item).html());}}
if(sameAsText){opts.selectedValue=_selectedText;_dropdownValue.val(_selectedText);}
else
opts.selectedValue=_dropdownValue.val();if(notfire)return;self.element.trigger("selectedChanged",{value:opts.selectedValue,text:_staticTxt.text(),index:opts.selectedIndex,srcElement:_item});},open:function(){var opts=this.options,_el=this.element;_el.trigger("beforeDropdownOpen");_el.addClass("ui-state-active ui-corner-top").removeClass("ui-corner-all")
if(opts.container){var _container=$(opts.container,_el);if(_container.length){if(_container.height()>opts.minHeight)
_container.height(opts.minHeight);if($.browser.msie)
_container.css({"overflow-x":"hidden","overflow-y":"auto"});else
_container.css({"overflow":"auto"});_container.slideDown("fast").position({of:$(_el),my:"left top",at:"left bottom"});}}
_el.trigger("afterDropdownOpen");},close:function(){var opts=this.options,_el=this.element;_el.trigger("beforeDropdownClose");_el.removeClass("ui-state-active ui-corner-top").removeClass(opts.highlightClass).addClass("ui-corner-all");if(opts.container){var _container=$(opts.container,_el);if(_container.length>0)
_container.slideUp("fast");}
_el.trigger("afterDropdownClose");},setText:function(v){$(">.ui-dropdown-text",this.element).text(v);},destroy:function(){var opts=this.options,_el=this.element;_el.unbind();_el.removeClass("ui-dropdown");_el.removeClass("ui-corner-all");_el.removeClass("ui-state-default");if(opts.items){var _items=$(opts.items,_el);if(_items.length>0){_items.unbind();}}
if(opts.container){if($(opts.container,this.element).lenth>0){if($(opts.container,this.element).resizable)
$(opts.container,this.element).resizable("destory");}}
$(">ui-dropdown-icon",_el).remove();$(">ui-dropdown-text",_el).remove();var _valuebox=$("input[name='"+$(this.element).attr("id")+"']",this.element);if(_valuebox.length>0){_valuebox.unbind();_valuebox.remove();}
$.Widget.prototype.destroy.call(this);}});$.widget("ui.editable",{options:{submit:null,cancel:null},_create:function(){var self=this,opts=this.options,el=this.element;if(opts.submit)
el.bind("submitchanged",opts.submit);if(opts.cancel)
el.bind("canceledit",opts.cancel);el.bind("click",function(){self.edit();});},edit:function(){var el=this.element,self=this;if(el.attr("editing"))
return;el.attr("editing",true);var $editbox=$("<input type='text' />");$editbox.css({"border":"none","background":"none","dipslay":"inline"});var _innerText=el.text();$editbox.val(_innerText);$editbox.css({"font-family":el.css("font-family"),"color":el.css("color")});el.data("_text",_innerText);el[0].innerHTML="";el.append($editbox);$editbox.bind("keypress",function(event){if(event.keyCode==13)self._submitchange();if(event.keyCode==27)self._canceledit();});$editbox.bind("blur",function(){self._submitchange();});$editbox.focus();var txtRange=$editbox[0].createTextRange();txtRange.select();},_canceledit:function(){var el=this.element;this._removeEditor();this.element.text(el.data("_text"));this.element.trigger("canceledit");this.element.removeAttr("editing");},_removeEditor:function(){var el=this.element;var $input=el.find("input");$input.unbind();$input.remove();},_submitchange:function(){var el=this.element;var $input=el.find("input");el.text($input.val());el.trigger("submitchanged",$input.val());el.removeAttr("editing");this._removeEditor();},destroy:function(){this.element.unbind();$.Widget.prototype.destroy.call(this);}});$.widget("ui.inputFilter",{options:{number:false,maxlength:false,decimalDigits:0,mode:"validchars",validChars:null,invalidChars:null},_create:function(){var self=this,opts=this.options,el=this.element;var numChars="1234567890";if(opts.number){if(isNaN(parseInt(el.val())))
el.val(self._getDefaultValue());el.bind("change",function(){if(isNaN(parseInt(el.val())))
el.val(self._getDefaultValue());});}
if(opts.maxlength){el.attr("maxlength",opts.maxlength);}
el.bind("keydown",function(event){var _c=event.keyCode;var ignores=[8,9,16,17,18,46,37,38,39,40];for(var ig=0;ig<ignores.length;ig++){if(ignores[ig]==_c)
return true;}
if(opts.number){if(_c==190||_c==110){if(opts.decimalDigits==0)
return false;if(el.val().indexOf(".")>-1)
return false;}
var _smallPads=[96,97,98,99,100,101,102,103,104,105];for(var s=0;s<_smallPads.length;s++){if(_smallPads[s]==_c)
return true;}
return self._isValid(numChars,_c);}
if(opts.mode=="validchars"){if(opts.validChars)
return self._isValid(opts.validChars,_c);}else{if(opts.invalidChars)
return!self._isValid(opts.invalidChars,_c);}});},_getDefaultValue:function(){var v="0";if(this.options.decimalDigits){v+=".";for(var d=0;d<this.options.decimalDigits;d++){v=v+"0";}}
return v;},_isValid:function(chars,code){for(var i=0;i<chars.length;i++){if(chars.charCodeAt(i)==code)
return true;}
return false;},destroy:function(){this.element.unbind("keypress");$.Widget.prototype.destroy.call(this);}});$.widget("ui.listview",{options:{multiselect:false,showCheckbox:false,itemEditable:false,items:">li",itemText:"div:last",itemImg:"img",itemValue:"input[type='hidden']",itemClass:"ui-state-default ui-corner-all",itemWidth:0,itemHeight:0,hoverClass:"ui-state-hover",selectedClass:"ui-state-active",selectedItem:null,selectedValue:null,tooltipClass:"ui-state-highlight ui-corner-all",itemDblClick:null,itemClick:null,editCompleted:null},_create:function(){var self=this,opts=this.options,el=this.element,eventPrefix=this.widgetEventPrefix;el.addClass("ui-listview").css({"overflow":"auto"});if(!opts.items)
throw"Item selector not set the listview init fail!";var items=$(opts.items,this.element);items.addClass("ui-listview-item");items.css({height:opts.itemHeight?opts.itemHeight:100,width:opts.itemWidth?opts.itemWidth:80});if((opts.itemClass!=undefined)&&(opts.itemClass!=""))
items.addClass(opts.itemClass);if($.fn.tooltip)
items.tooltip({delay:0,extraClass:opts.tooltipClass});if(opts.hoverClass!=""){items.hover(function(){$(this).addClass(opts.hoverClass);},function(){$(this).removeClass(opts.hoverClass);});}
if((opts.selectedClass==undefined)||(opts.selectedClass==""))
opts.selectedClass="ui-listview-item-selected";items.each(function(i,n){var _txtEl=null;var _valEl=null;var _n=$(n);var args={text:"",value:"",item:_n,index:i};if(_n.attr("selected"))
_n.addClass(opts.selectedClass);if(opts.itemText){_txtEl=$(opts.itemText,n);if(_txtEl.length>0){_txtEl.addClass("ui-listview-item-text");args.text=_txtEl.text();}}
if(opts.itemValue){_valEl=$(opts.itemValue,n);if(_valEl.length>0){args.value=_valEl.val();}
if(opts.selectedValue){if(_valEl.val()==opts.selectedValue)
_n.addClass(opts.selectedClass);}}
_n.bind("dblclick",function(){el.trigger(eventPrefix+"itemDblclick",args);if(opts.itemEditable){if(_txtEl){if(_txtEl.length>0){if($.fn.editable){_txtEl.editable({submit:function(){el.trigger(eventPrefix+"itemEditCompleted",args);}});}}}}});_n.bind("click",function(){opts.selectedItem=args;el.trigger(eventPrefix+"itemClick",args);if(opts.selectedClass){items.removeClass(opts.selectedClass);_n.addClass(opts.selectedClass);}});});if(opts.itemClick)
el.bind(eventPrefix+"itemClick",opts.itemClick);if(opts.itemDbClick)
el.bind(eventPrefix+"itemDbClick",opts.itemDbClick);},destroy:function(){$(this.element).unbind();if(this.options.items){var _items=$(this.options.items,this.element);if(_items.length)_items.unbind();}
$.Widget.prototype.destroy.call(this);}});$.widget("ui.markupable",{options:{imgBaseUrl:"/Content/Images/wiki/",parserUrl:"/Shared/Public/Parsers/wiki.txt",width:"auto",height:300,bgColor:"white"},_create:function(){this._buildEditor();this._buildToolbar();},_insertMarkup:function(_markup){if($.browser.msie){this.element.focus();this.curSelection=document.selection.createRange();this.curSelection.text=_markup.Syntax.replace("{0}",this.curSelection.text);}
else{var e=this.element[0];if(e.selectionEnd){var _start=e.selectionStart,_end=e.selectionEnd,_rep=_markup.Syntax.replace("{0}",e.value.substring(_start,_end)),_pre=e.value.substring(0,_start),_last=e.value.substring(_end);e.value=_pre+_rep+_last;}}},_buildEditor:function(){var self=this,opts=this.options,el=this.element,_w=(opts.width=="auto"||opts.width=="100%")?"100%":(opts.width+5)+"px",_container=$("<div></div>").appendTo(el.parent()).addClass("ui-markupable").css({"background-color":opts.bgColor,"display":"block"});el.appendTo(_container);el.css({width:_container.width(),height:(opts.height+56)+"px","background-color":opts.textBGColor,"border":"none"});if(self.isIE()){var ieW=(opts.width=="auto"||opts.width=="100%")?"100%":(opts.width+3)+"px";el.css({"overflow":"auto",width:ieW});}
this._container=_container;_container.resizable({alsoResize:this.element,handles:"n,s"});},isGecko:function(){return(navigator.userAgent.indexOf('Gecko')!=-1)?true:false;},isIE:function(){return $.browser.msie;},widget:function(){return this._container;},_createToolbarButton:function(_markup,fn){var self=this,_fullUrl=this.options.imgBaseUrl+_markup.Icon;var _buttonClick=function(){self._insertMarkup(_markup);};if($.isFunction(fn))
_buttonClick=fn;if(this._toolbar){var hoverCss={"border-width":"1px","border-color":"#cccccc","border-style":"solid"},defaultCss={"border-width":"1px","border-color":"#FFFFFF","border-style":"solid"};return $("<li/>").appendTo(this._toolbar).addClass("ui-helper-reset").css({"float":"left","margin-right":"1px","padding":"5px","border-width":"1px","border-color":"#FFFFFF","border-style":"solid"}).hover(function(){$(this).css(hoverCss);},function(){$(this).css(defaultCss);}).append($("<img/>").attr("src",_fullUrl).attr("title",_markup.Remarks?_markup.Remarks:"").css({cursor:"pointer",height:"16px",width:"16px"}).bind("click",_buttonClick));}},_buildToolbar:function(){var self=this;if(this._container){this._toolbar=$("<ul></ul>").prependTo(this._container).addClass("ui-helper-reset").addClass("ui-markupable-toolbar").css({display:"block",float:"left",margin:"0px",padding:"5px","padding-left":"0px","padding-right":"0px","position":"relative","border-width":"1px","border-color":"#cccccc","border-style":"solid",width:this._container.width()-2});$.ajax({url:this.options.parserUrl,success:function(data){var p=eval(data);$.each(p.Markups,function(i,n){if(n.Icon)
self._createToolbarButton(n);});}});}}});$.widget("ui.menu",{options:{type:"horizontal",target:null,dropdownEvent:"click",topMenuClass:"ui-corner-top",topItemClass:"ui-state-default ui-corner-top",topItemHoverClass:"ui-state-active",topItemSelectedClass:"ui-state-active",subMenuClass:"ui-widget-content",subMenuItemClass:"ui-state-default",subMenuItemHoverClass:"ui-state-active",beforeOpen:null,open:null,beforeClose:null,close:null,itemClick:null,spliterIconClass:"ui-icon ui-icon-carat-1-e",showSpliter:false},_create:function(){var self=this,opts=this.options,el=this.element,_topItems=$(">li",el);if($.fn.bgiframe)
el.bgiframe();if(opts.beforeOpen)
el.bind("menubeforeOpen",opts.beforeOpen);if(opts.open)
el.bind("menuopen",opts.open);if(opts.beforeClose)
el.bind("menubeforeClose",opts.beforeClose);if(opts.close)
el.bind("menuclose",opts.close);if(opts.itemClick)
el.bind("menuitemclick",opts.itemClick);if(_topItems.length){if(opts.type=="horizontal"){el.css({"float":"left"});_topItems.each(function(){self._initHorizontalTopItem(this);if(opts.showSpliter){if(i<_topItems.length-1){var _spliter=$("<li></li>").css({"float":"left","padding":"5px"}).append($("<span></span>").addClass(opts.spliterIconClass));$(this).after(_spliter);}}
self._initSubItems(this);});}
else{if(opts.topMenuClass)
el.addClass(opts.topMenuClass);_topItems.each(function(){self._initVerticalTopItem(this);self._initSubItems(this);});if(opts.type=="dropdown"){if(opts.target)self._initDropdownMenu();}
else{if(opts.target)self._initContextMenu();}}}
var _allItems=$("li",el);if(_allItems.length)
_allItems.bind("click",function(){el.trigger("menuitemclick",this);});},_initContextMenu:function(){var self=this,opts=this.options,el=this.element;el.appendTo("body");el.css({"display":"none","position":"absolute"});var _target=null;if(opts.target.jquery)
_target=opts.target;else
_target=$(opts.target);_target.bind("contextmenu",function(event){event.preventDefault();});_target.bind("mouseup",function(event){if(event.button==2){var _offset=_target.offset();el.css({"top":_offset.top+_target.height(),"left":_offset.left,"z-index":"5000"}).slideDown("normal");}});el.bind("mouseleave",function(){el.slideUp("normal");});},_initDropdownMenu:function(){var self=this,opts=this.options,el=this.element;el.appendTo("body");el.css({"display":"none","position":"absolute"});var _target=null;if(opts.target.jquery)
_target=opts.target;else
_target=$(opts.target);if(_target.length){var _e="click";if(opts.dropdownEvent)
_e=opts.dropdownEvent;_target.bind(_e,function(){var _offset=_target.offset();el.css({"top":_offset.top+_target.height(),"left":_offset.left,"z-index":"5000"}).slideDown("fast");});el.bind("mouseleave",function(){el.slideUp("fast");});}},_initVerticalTopItem:function(oTop){var _item=$(oTop),self=this,opts=this.options,el=this.element;if(opts.topItemClass){_item.addClass(opts.topItemClass).css({"position":"relative"});}
var _itemlink=$(">a",_item);_itemlink.css({"display":"inline-block"});if($("ul",_item).length){$("<span></span>").appendTo(_item).addClass("ui-icon ui-icon-carat-1-e").css({"right":"0px","margin-top":"-8px","position":"absolute","top":"50%"});}
_item.bind("mouseenter",function(){$(this).addClass(opts.topItemHoverClass);self._showMenu(this);});_item.bind("mouseleave",function(){$(this).removeClass(opts.topItemHoverClass);self._hideMenu(this);});},_initHorizontalTopItem:function(oTop){var _item=$(oTop),self=this,opts=this.options,el=this.element,_topClass=opts.topItemClass;if(_item.attr("selected")){_topClass=opts.topItemSelectedClass;}
_item.addClass(_topClass)
_item.css({"float":"left","position":"relative"});var _itemlink=$(">a",_item);_itemlink.css({"display":"inline-block"});_item.bind("mouseenter",function(event){$(this).removeClass(opts._topClass);$(this).addClass(opts.topItemHoverClass);self._showTopMenu(this);event.stopPropagation();});_item.bind("mouseleave",function(event){$(this).removeClass(opts.topItemHoverClass);$(this).addClass(_topClass);self._hideTopMenu(this);event.stopPropagation();});},_initSubItems:function(oParent){var _item=$(oParent),self=this,opts=this.options,el=this.element,_sub=$("ul",_item);if(_sub.length){if($.fn.bgifame)
_sub.bgiframe();_sub.css({"position":"absolute","left":"0px","padding":"0px","z-index":2000,top:_item.find("a").outerHeight(true)+10});if(opts.subMenuClass)
_sub.addClass(opts.subMenuClass);var _subItems=$(">li",_sub);if(_subItems.length){_subItems.each(function(){var _subItem=$(this);if(opts.subMenuItemClass)
_subItem.addClass(opts.subMenuItemClass);_subItem.css({"padding":"0","white-space":"nowrap","position":"relative"});var _subItemLink=$(">a",_subItem);_subItemLink.css({"display":"inline-block"});if($("ul",_subItem).length){$("<span></span>").appendTo(_subItem).addClass("ui-icon ui-icon-carat-1-e").css({"right":"0px","margin-top":"-8px","position":"absolute","top":"50%"});}
_subItem.bind("mouseenter",function(){$(this).removeClass(opts.subMenuItemClass);$(this).addClass(opts.subMenuItemHoverClass);self._showMenu(this);});_subItem.bind("mouseleave",function(){$(this).removeClass(opts.subMenuItemHoverClass);$(this).addClass(opts.subMenuItemClass);self._hideMenu(this);});});}
_sub.each(function(){var _s=$(this);_s.attr("h",_s.height()).attr("w",_s.width()).css({"display":"none"});});}},_showTopMenu:function(_item){this.element.trigger("menubeforeOpen",_item);var subMenu=$(">ul",_item);if(subMenu.length==1){var _top=0,_left=$(_item).width();_left=0;_top=$(_item).height();subMenu.css({"top":_top+"px","left":_left+"px","z-index":"5000"});subMenu.slideDown("fast");}
this.element.trigger("menuopen",_item);},_showMenu:function(_item){this.element.trigger("menubeforeOpen",_item);var subMenu=$(">ul",_item);if(subMenu.length==1){_top=0,_left=$(_item).width();subMenu.fadeIn("fast");subMenu.css({"top":_top+"px","left":_left+"px","z-index":"5000"});}
this.element.trigger("menuopen",_item);},_hideTopMenu:function(_parent){this.element.trigger("menubeforeClose",_parent);var subMenu=$(">ul",_parent);if(subMenu.length)
subMenu.slideUp("fast");this.element.trigger("menuclose",_parent);},_hideMenu:function(_parent){this.element.trigger("menubeforeClose",_parent);var subMenu=$(">ul",_parent);if(subMenu.length){subMenu.slideUp("fast");}
this.element.trigger("menuclose",_parent);},_checkParent:function(oParent){var _parent=null;if(oParent){var _ul=$(">ul",oParent);if(_ul.length==0)
_ul=$("<ul></ul>").appendTo(oParent);_parent=_ul;}else
_parent=this.element;return _parent;},addItem:function(oParent,oItem){var _parent=this._checkParent(oParent),_dom=$("<li></li>").appendTo(_parent)
$("<a></a>").appendTo(_dom).attr("href",oItem.url?oItem.url:"#").text(oItem.text?oItem.text:"");},destroy:function(){this.element.unbind();$("li",this.element).unbind();$.Widget.prototype.destroy.call(this);}});$.widget("ui.pager",{options:{totalpages:50,totalrecords:0,pageindex:1,pagesize:20,changed:null},_create:function(){var self=this,opts=this.options,el=this.element,eventPrefix=this.widgetEventPrefix;el.css({height:25});opts.totalpages=parseInt(Math.round(opts.totalrecords/opts.pagesize));if($.isFunction(opts.changed)){el.bind(eventPrefix+"changed",opts.changed);}
var $ul=$("<ul></ul>").appendTo(el).addClass("ui-helper-reset"),$first=$("<li></li>").appendTo($ul).addClass("ui-pager-first").append($("<span></span>").addClass("ui-icon ui-icon-triangle-1-w")),$prev=$("<li></li>").appendTo($ul).addClass("ui-pager-prev").append($("<span></span>").addClass("ui-icon ui-icon-carat-1-w")),$last=$("<li></li>").addClass("ui-pager-last").append($("<span></span>").addClass("ui-icon ui-icon-triangle-1-e")),$next=$("<li></li>").addClass("ui-pager-next").append($("<span></span>").addClass("ui-icon ui-icon-carat-1-e"));$first.bind("click",function(){self.go(1,$(this));$first.hide();$prev.hide();$last.show();$next.show();});$prev.bind("click",function(){self.go(opts.pageindex-1,$(this));if(opts.pageindex==1){$first.hide();$prev.hide();$last.show();$next.show();}
else{$last.show();$next.show();}});if(opts.pageindex==1){$first.hide();$prev.hide();}
var _range=this._updateRange();for(i=_range[0];i<=_range[1];i++){var $num=$("<li>"+i.toString()+"</li>").appendTo($ul).addClass("ui-page-num").attr("index",i);if(opts.pageindex==i)
$num.addClass("ui-state-active");$num.bind("click",function(){self.go(parseInt($(this).attr("index")),$(this));});}
$ul.append($next);$ul.append($last);$last.bind("click",function(){self.go(opts.totalpages,$(this));$first.show();$prev.show();$last.hide();$next.hide();});$next.bind("click",function(){self.go(opts.pageindex+1,$(this));if(opts.pageindex==opts.totalpages){$first.show();$prev.show();$last.hide();$next.hide();}
else{$prev.show();$first.show();}});if(opts.pageindex==opts.totalpages){$last.hide();$next.hide();}
var _btns=$(">li",$ul);_btns.each(function(){var _btn=$(this);_btn.addClass("ui-state-default").css({"float":"left",width:16,cursor:"pointer",margin:"1px",padding:"3px","text-align":"center"});_btn.hover(function(){$(this).addClass("ui-state-hover");},function(){$(this).removeClass("ui-state-hover");});});},_updateRange:function(){var opts=this.options,startAt=1,end=11;while(opts.pageindex>=end){startAt=startAt+10;end=end+10;}
if(end>opts.totalpages)
end=opts.totalpages;this.range=[startAt,end];return this.range;},destroy:function(){this.element.unbind();$("ul>li",this.element).unbind();$.Widget.prototype.destroy.call(this);},_refresh:function(){var _range=this._updateRange(),opts=this.options,_nums=$(".ui-page-num",this.element);_nums.removeClass("ui-state-active");_nums.each(function(i,n){_index=i+_range[0];$(this).attr("index",_index).text(_index);if(_index==opts.pageindex)
$(this).addClass("ui-state-active");});},go:function(_index,_btn){var opts=this.options,self=this,el=this.element,eventPrefix=this.widgetEventPrefix;opts.pageindex=_index;el.trigger(eventPrefix+"changed",{pageIndex:_index,pageSize:opts.pagesize});if(_btn.hasClass("ui-page-num")){$("li",el).removeClass("ui-state-active");_btn.addClass("ui-state-active");}else{if(_index>this.range[1]){}
this._refresh();}}});$.widget("ui.portable",{options:{items:".ui-widget-zone",url:null,mode:null},_create:function(){var self=this,opts=this.options,el=this.element,service=portal.dynamicUI,_zones=this.element.find(opts.items);if(_zones.length>0){portal.dynamicUI.zones=_zones;if(opts.mode=="design"){_zones.sortable({connectWith:opts.items,placeholder:"ui-widget-placeholder",forceHelperSize:true,forcePlaceholderSize:true,revert:true,opacity:0.8,helper:'clone',cursor:"move",handle:"h3",update:function(event,ui){try{var widgets=$(".dna-ui-widget",this),_pos=-1,__id=ui.item.portlet("option","title");if(widgets.length>0)
_pos=widgets.index(ui.item);if(_pos!=-1)
ui.item.portlet("move",$(this).attr("id"),_pos);}
catch(e){$(ui.sender).sortable('cancel');}}});_zones.css({"border-color":"#cccccc","border-width":"1px","border-style":"dashed","min-height":"200px"}).droppable({accept:".dna-ui-widget",activeClass:"ui-state-default",hoverClass:"ui-state-highlight"});}
$.ajax({url:opts.url,cache:false,data:{url:document.URL,mode:opts.mode},dataType:"json",error:function(response){uiHelper.showDlg(response.statusText,response.responseText);},success:function(data){if(data){if(data["auth"]==false){_zones.sortable("destroy");_zones.droppable("destroy");}
_zones.each(function(i,n){var _zname=$(n).attr("id");if(data[_zname]){var __widgets=JSON.parse(data[_zname]);for(var j=0;j<__widgets.length;j++){var wdata=__widgets[j];if(opts.mode!="design"){if(!wdata.expanded)
continue;}
$("<div><div>").appendTo($(n)).attr("id",wdata.id).portlet(wdata);}}});}}});}}});$.widget("ui.portlet",{options:{icons:{collapse:"ui-icon ui-icon-triangle-1-n",expand:"ui-icon ui-icon-triangle-1-s","export":"ui-icon ui-icon-disk","delete":"ui-icon ui-icon-close",refresh:"ui-icon ui-icon-refresh",settings:"ui-icon ui-icon-wrench"},classes:{header:"dna-ui-widget-header",body:"dna-ui-widget-body",footer:"dna-ui-widget-footer"},closable:true,deletable:true,expanded:true,showFooter:true,pos:0,showHeader:true,showBorder:true,bgColor:"",color:"",title:"",titlelink:"",url:"",preview:false,design:false,zoneId:"",baseUrl:null,exportActionUrl:"Export",applyActionUrl:"Apply",moveActionUrl:"MoveTo",removeActionUrl:"Delete",toggleActionUrl:"Toggle"},_create:function(){var self=this,opts=this.options,el=this.element;if(opts.baseUrl){opts.exportActionUrl=opts.baseUrl+opts.exportActionUrl;opts.applyActionUrl=opts.baseUrl+opts.applyActionUrl;opts.moveActionUrl=opts.baseUrl+opts.moveActionUrl;opts.removeActionUrl=opts.baseUrl+opts.removeActionUrl;opts.toggleActionUrl=opts.baseUrl+opts.toggleActionUrl;}
if(!el.hasClass("dna-ui-widget"))
el.addClass("dna-ui-widget");this.verbs={};this._buildHeader();this._initHeader();this._buildBody();if(this.options.expanded){this._load();}
else{if(this.body){this.body.hide();this._isloaded=false;}}
this._buildFooter();},_buildHeader:function(){var opts=this.options;if(!opts.design&&!opts.showHeader)return;this.header=$("<h3></h3>").addClass(opts.classes.header);this.element.append(this.header);this._buildTitle();this._buildMenu();},_buildTitle:function(){if(this.header){var opts=this.options,w_title=$("<a href=\"#\">"+opts.title+"</a>");if(opts.titlelink){w_title.attr("target","_blank").attr("href",opts.titlelink);if(!opts.design)
w_title.css({"cursor":"default"});}
if(opts.icon){this.titleicon=$("<span></span>").appendTo(w_title).addClass("dna-ui-widget-icon").css({"width":"16px","height":"16px","float":"left","margin-right":"3px","background-image":"url("+opts.icon+")"});}
this.title=w_title;this.header.append(w_title);}},_buildMenu:function(){if(this.options.design&&this.header){this.headerMenu=$("<ul></ul>").appendTo(this.header);this._buildToggleVerb();this._buildDeleteVerb();this._buildRefreshVerb();this._buildExportVerb();}},_buildExportVerb:function(){var self=this;if(this.headerMenu){this.verbs.exportVerb=this._createVerb("Export user preference settings",this.options.icons["export"],function(){self._export();});this.headerMenu.append(this.verbs.exportVerb);}},_buildDeleteVerb:function(){var self=this,el=this.element;if(this.headerMenu&&this.options.deletable){this.verbs.deleteVerb=this._createVerb("Delete",this.options.icons["delete"],function(){self._delete();});this.headerMenu.append(this.verbs.deleteVerb);}},_buildToggleVerb:function(){var self=this;if(this.headerMenu&&this.options.closable){var _t="Collapse and hide",_icon="ui-icon ui-icon-triangle-1-s";if(!this.options.expanded){_t="Expand and show";_icon="ui-icon ui-icon-triangle-1-s";}
this.verbs.toggleVerb=this._createVerb(_t,_icon,function(){self._toggleCollapse();});this.headerMenu.append(this.verbs.toggleVerb);}},_buildRefreshVerb:function(){var self=this;if(this.headerMenu){this.verbs.refreshVerb=this._createVerb("Refresh",this.options.icons.refresh,function(){self._refresh();});this.headerMenu.append(this.verbs.refreshVerb);}},_buildSettingVerb:function(){if(this.headerMenu){var self=this;if(this.verbs.settingVerb)
this.verbs.settingVerb.remove();this.verbs.settingVerb=this._createVerb("Show settings",this.options.icons.settings,function(){$(this).hide();if(self.settings)
self.settings.slideDown("fast");});this.headerMenu.append(this.verbs.settingVerb);}},_buildBody:function(){this.body=$("<div></div>").appendTo(this.element).addClass(this.options.classes.body).append("<div class='dna-loader'><div>");},_buildFooter:function(){var self=this;if(this.options.design&&this.options.showFooter){var _footer=$("<div></div>").appendTo(this.element).addClass(this.options.classes.footer).css({"border-top":"none","padding":"0px"});$("<a></a>").appendTo(_footer).actionLink({icon:"ui-icon ui-icon-gear",text:"Settings",click:function(){self._showSettingDlg();}});if(!this.options.expanded)
_footer.hide();this.footer=_footer;}},doVerb:function(vn){if(this.verbs[vn]){var _icon=this.verbs[vn].find("span");if(_icon.length)_icon.click();}},_createVerb:function(_title,_iconClass,_clickHandler){return $("<li></li>").append($("<span></span>").addClass(_iconClass).attr("title",_title)).bind("click",_clickHandler);},_createSettingDlg:function(){var _settingDlg=$("<div></div>").appendTo("body").attr("title","Widget settings"),self=this,opts=this.options,_form=$("<form></form>").attr("action",opts.applyActionUrl).appendTo(_settingDlg),prefix="widgetsettingsdlg",_changed={}
$("<div></div>").appendTo(_form).text("Title");$("<input />").attr("type","text").attr("id",prefix+"_title").attr("name","title").appendTo(_form).textbox({value:opts.title,changed:function(){_changed.title=$(this).val();}});$("<div></div>").appendTo(_form).text("Title link url");$("<input />").attr("id",prefix+"_titlelink").attr("name","titleLinkUrl").attr("type","text").appendTo(_form).textbox({value:opts.titlelink,changed:function(event){_changed.titlelink=$(this).val();}});$("<div></div>").appendTo(_form).text("Icon url");$("<input />").attr("id",prefix+"_iconurl").attr("name","iconUrl").attr("type","text").appendTo(_form).textbox({value:opts.icon,changed:function(event){_changed.icon=$(this).val();}});var bgContainer=$("<div></div>").appendTo(_form).css({"margin-top":"5px"}).text("Background color:");$("<input />").attr("id",prefix+"_bgColor").attr("name","backgroundColor").attr("type","text").attr("value",opts.bgColor).css({"width":"50px","padding":"3px","border":"0px","font-size":"9pt"}).appendTo(bgContainer).change(function(){_changed.bgColor=$(this).val();}).focus(function(){$("#bgColorPicker").show().css({"position":"absolute","top":"auto","z-Index":"2000"});}).blur(function(){$("#bgColorPicker").hide();});$("<div/>").appendTo(_form).addClass("farbtastic").addClass("ui-corner-all").addClass("ui-widget-content").css({"display":"none"}).attr("id","bgColorPicker").farbtastic("#"+prefix+"_bgColor");var _fontColorContainer=$("<div></div>").appendTo(_form).css({"margin-top":"5px"}).text("Font color");$("<input />").attr("id",prefix+"_foreColor").attr("name","foreColor").attr("type","text").attr("value",opts.color).css({"width":"50px","padding":"3px","border":"0px","font-size":"9pt"}).appendTo(_fontColorContainer).change(function(){_changed.color=$(this).val();}).focus(function(){$("#fontColorPicker").show().css({"position":"absolute","top":"auto","z-Index":"2000"});}).blur(function(){$("#fontColorPicker").hide();});$("<div/>").appendTo(_form).addClass("farbtastic").addClass("ui-corner-all").addClass("ui-widget-content").css({"display":"none"}).attr("id","fontColorPicker").farbtastic("#"+prefix+"_foreColor");var _sh=$("<div></div>").appendTo(_form).css({"margin-bottom":"2px"});$("<input />").attr("id",prefix+"_showHeader").attr("name","showHeader").attr("type","hidden").appendTo(_sh).checkbox({text:"Show header",value:opts.showHeader,changed:function(event,value){_changed.showHeader=value;}});var _sb=$("<div></div>").appendTo(_form).css({"margin-bottom":"2px","clear":"left"});$("<input />").attr("id",prefix+"_showBorder").attr("name","showBorder").attr("type","hidden").appendTo(_sb).checkbox({text:"Show border",value:opts.showBorder,changed:function(event,value){_changed.showBorder=value;}});var _sc=$("<div></div>").appendTo(_form).css({"margin-bottom":"2px","clear":"left"});$("<input />").attr("id",prefix+"_closable").attr("name","isClosable").attr("type","hidden").attr("value","true").appendTo(_sc);_settingDlg.getChanges=function(){return _changed;};return _settingDlg;},_export:function(){window.open(this.options.exportActionUrl+"?wid="+this.options.id);},_refresh:function(){if(this.body){this.body.html("<div class=\"dna-loader\"><div>");this._load();}},_delete:function(){var self=this,el=this.element;uiHelper.confirm("Are you sure?","Are you sure to delete this widget?",function(){$.post(self.options.removeActionUrl,{id:self.options.id},function(){self.destroy();el.remove();});});},_toggleCollapse:function(){if(this.body)
this.body.slideToggle("fast");this.verbs.toggleVerb.find("span").toggleClass("ui-icon-triangle-1-n");this.verbs.toggleVerb.find("span").toggleClass("ui-icon-triangle-1-s");if(this.header)
this.header.toggleClass("ui-corner-bottom").toggleClass("ui-corner-all");$.post(this.options.toggleActionUrl,{id:this.element.attr("id")});this.options.expanded=!this.options.expanded;if(this.options.expanded){if(this.verbs.settingVerb)
this.verbs.settingVerb.show();this.verbs.refreshVerb.show();if(!this._isloaded){this.body.slideDown("fast");var self=this;window.setTimeout(function(){self._load();},500);}}
else{if(this.verbs.settingVerb)
this.verbs.settingVerb.hide();this.verbs.refreshVerb.hide();}
if(this.footer){if(this.options.expanded)
this.footer.show();else
this.footer.hide();}},_load:function(){var self=this,opts=this.options;$.ajax({url:opts.url,data:{wid:opts.id,preview:opts.preview,design:opts.design},error:function(response,textStatus,errorThrown){self.body.html(response.responseText);},success:function(htm){self._initBody(htm);self._isloaded=true;}});},_apply:function(){var opts=this.options;this.title.text(opts.title);if(opts.titlelink)
this.title.attr("href",urlHelper.encode(opts.titlelink));else
this.title.attr("href","javascript:void(0);");if(opts.icon)
this.titleicon=$("<span></span>").prependTo(this.title).css({"width":"16px","height":"16px","float":"left","margin-right":"3px","background-image":"url("+opts.icon+")"});if(!this.options.showHeader)this.header.css({opacity:"0.5"});this._initBodyStyle();},_showSettingDlg:function(){var self=this,opts=this.options,_dlg=this._createSettingDlg(),_form=$("form",_dlg);_dlg.dialog({bgiframe:true,show:"slide",hide:"puff",resizable:false,modal:true,close:function(){$(this).remove();},buttons:{"OK":function(){$.ajax({type:"POST",url:_form.attr('action')+"/"+opts.id,data:_form.serialize(),error:function(response){uiHelper.showDlg(response.statusText,response.responseText);},success:function(){$.extend(self.options,_dlg.getChanges());self._apply();_dlg.dialog("close");}});},"Cancel":function(){$(this).dialog("close");}}});},_initBodyStyle:function(){var opts=this.options;if(this.body){if(opts.bgColor)
this.body.css({"background-color":opts.bgColor,"background-image":"none"});if(opts.color)this.body.css({"color":opts.color});if(opts.showHeader)
this.body.css({"border-top-style":"solid","border-top-width":"1px","border-top-color":"transparent"});if(opts.design){if(!opts.showBorder)
this.body.css({"border-style":"dashed"});}
else{if(!opts.showBorder)
this.body.css({"border":"none"});}
if(!opts.expanded)this.body.hide();}},_initBody:function(_html){var self=this,opts=this.options;if(this.body){this.body.html(_html);this._initBodyStyle();if(this.options.design){var settings=$(".ui-widget-settings",this.element);if(settings.length>0){this.settings=settings;settings.hide();if(opts.design){this._buildSettingButtonPanel();this._buildSettingVerb();if(!opts.expanded){if(this.verbs.settingVerb)this.verbs.settingVerb.hide();}}}}}},_initHeader:function(){if(this.header){this.header.css({margin:"0px"});if(!this.options.design){this.header.css({"cursor":"default"});if(this.options.titlelink)
this.title.css({"cursor":"pointer"});else this.title.css({"cursor":"default"});}
else{if(!this.options.showHeader)this.header.css({opacity:"0.5"});}
if(this.options.expanded){this.header.addClass("ui-corner-top");if(this.options.design){if(this.verbs.toggleVerb)
this.verbs.toggleVerb.find("span").removeClass("ui-icon-triangle-1-s").addClass("ui-icon-triangle-1-n");}}
else{this.header.addClass("ui-corner-all");if(this.options.design){this.verbs.refreshVerb.hide();if(this.verbs.toggleVerb)
this.verbs.toggleVerb.find("span").removeClass("ui-icon-triangle-1-n").addClass("ui-icon-triangle-1-s");}}}},_initFooter:function(){},_buildSettingButtonPanel:function(){var self=this,opts=this.options;if(this.settings){if(this.settings.buttonPanel)this.settings.buttonPanel.remove();this.settings.buttonPanel=$("<div></div>").appendTo(this.settings).css({"overflow":"auto","padding":"5px"});self.settings.submit(function(e){if(!e.isDefaultPrevented()){$.ajax({type:"PUT",url:opts.url+"?wid="+opts.id+"&preview="+opts.preview,data:self.settings.serialize(),error:function(response){uiHelper.showDlg(response.statusText,response.responseText);},success:function(){self.settings.slideUp("fast");self._refresh();}});}
e.preventDefault();});var _btnSave=$("<button/>").appendTo(this.settings.buttonPanel).click(function(event){event.preventDefault();self.settings.submit();}).button({label:"Save"});var _btnCancel=$("<button></button>").appendTo(this.settings.buttonPanel).click(function(event){event.preventDefault();self.settings.slideUp();self.verbs.settingVerb.show();}).button({label:"Cancel"});this.settings.buttonPanel.buttons={"Save":_btnSave,"Cancel":_btnCancel};}},move:function(zid,pos){$.ajax({type:"POST",url:this.options.moveActionUrl,data:{id:this.options.id,zoneID:zid,position:pos},error:function(response){uiHelper.showDlg(response.statusText,response.responseText);}});},widget:function(){return this.element;},destroy:function(){$(".ui-widget-menu",this.element).unbind();$.Widget.prototype.destroy.call(this);}});$.widget("ui.radio",{options:{value:true,text:"",radioClass:"ui-icon",selectedClass:"ui-icon-bullet",unselectedClass:"ui-icon-radio-on",change:null},_create:function(){var self=this,opts=this.options,$el=this.element;$el.disableSelection();$el.wrap("<div class='ui-radio' style='display:inline;'></div>");var _c=this._container=$el.parent();var _ico=$("<span style='float: left;' class='ui-radio-ico'></span>").addClass(opts.unselectedClass);var _txt=$("<span style='float: left;cursor:default;' class='ui-radio-text'>"+opts.text+"</span>");_c.append(_ico);_c.append(_txt);_c.attr("tabIndex","0");this._icon=$(".ui-radio-ico",_c);if(opts.radioClass)
this._icon.addClass(opts.radioClass);this._text=$(".ui-radio-text",_c);self._setValue(false);_ico.click(function(){opts.value=true;self._setValue(true);});_txt.click(function(){opts.value=true;self._setValue(true);});},clear:function(){var self=this,opts=this.options;opts.value=false;self._icon.removeClass(opts.selectedClass);self._icon.addClass(opts.unselectedClass);$(self.element).val(opts.value);},_setValue:function(fireEvent){var self=this,opts=this.options;if(opts.value==true){var _group=$(".ui-radio",self._container.parent());if(_group.length>0){_group.each(function(){$(">input[type='hidden']",this).radio('clear');});}
self._icon.removeClass(opts.unselectedClass);self._icon.addClass(opts.selectedClass);$(self.element).val(opts.value);if(_group.length>0){if(fireEvent){if(opts.change)
opts.change();}}}}});$.widget("ui.rating",{options:{value:0,maxrating:5,readOnly:false,starIcon:"ui-icon ui-icon-star",cssClass:"ui-state-default",hoverClass:"ui-state-active",change:null},_create:function(){var self=this,opts=this.options,el=this.element;if(opts.change)
this.element.bind("ratingchange",opts.change);_starts=$("<ul></ul>").appendTo(el).addClass("ui-helper-reset");if(!opts.readOnly){_starts.bind("mouseenter",function(){self.mouseOn=true;});_starts.bind("mouseleave",function(){self._setRatings(opts.value);self.mouseOn=false;});}
for(var i=1;i<opts.maxrating+1;i++){_start=$("<li></li>").appendTo(_starts).addClass(opts.cssClass).css({"float":"left","border":"none","background":"none","cursor":"pointer"}).attr("title",i).append($("<span></span>").addClass(opts.starIcon));if(!opts.readOnly){_start.hover(function(){self._setRatings(parseInt($(this).attr("title")));},function(){if(!self.mouseOn)
$(this).removeClass(opts.hoverClass);});_start.bind("click",function(){opts.value=parseInt($(this).attr("title"));el.trigger("ratingchange",opts.value);});}}
self._setRatings(opts.value);},_setRatings:function(_value){var opts=this.options,_starts=$("li",this.element);_starts.removeClass(opts.hoverClass);_starts.each(function(i,n){var _start=$(this),_rating=parseInt(_start.attr("title"));if(_rating<=_value)
_start.addClass(opts.hoverClass);});},setValue:function(_value){this._setRatings(_value);},destroy:function(){$("li",this.element).unbind();$(">ul",this.element).unbind().remove();$.Widget.prototype.destroy.call(this);}});$.widget("ui.richtextbox",{options:{mode:"editor",width:"auto",height:300,bgColor:"white",border:0,textFontSize:"12",textBGColor:"white",textFont:"Verdana, Arial, Helvetica",imgBaseUrl:"/content/images/rte/"},_create:function(){var self=this,opts=this.options,el=this.element;self.buildEditor();self.buildToolbar();self.initEditor(this.getText());self.toggleMode(opts.mode);},destroy:function(){$.Widget.prototype.destroy.call(this);},widget:function(){return this.rteContainer;},resource:{bold:{cmd:"Bold",icon:"icon_bold.gif",text:"Bold"},italic:{cmd:"Italic",icon:"icon_italic.gif",text:"Italic"},underline:{cmd:"Underline",icon:"icon_underline.gif",text:"Underline"},strikeThrough:{cmd:"StrikeThrough",icon:"icon_strikeThrough.gif",text:"StrikeThrough"},justifyLeft:{cmd:"JustifyLeft",icon:"icon_justifyLeft.gif",text:"Justify left"},justifyCenter:{cmd:"Justifycenter",icon:"icon_justifyCenter.gif",text:"Justify center"},justifyRight:{cmd:"JustifyRight",icon:"icon_justifyRight.gif",text:"Justify right"},justifyFull:{cmd:"Justifyfull",icon:"icon_justifyFull.gif",text:"Justify full"},indent:{cmd:"Indent",icon:"icon_indent.gif",text:"Indent"},outdent:{cmd:"Outdent",icon:"icon_outdent.gif",text:"Outdent"},orderList:{cmd:"InsertOrderedList",icon:"icon_orderedList.gif",text:"Insert Ordered List"},unorderList:{cmd:"InsertUnorderedList",icon:"icon_unorderedList.gif",text:"Insert Unordered List"},createLink:{cmd:"CreateLink",icon:"icon_link.gif",text:"Create Link"},toggleMode:{cmd:"toggle",icon:"icon_script.gif",text:"View source"},fontName:{cmd:"fontName",text:"Change the current font"},fontSize:{cmd:"fontSize",text:"Change the current font size"},fontColor:{cmd:"forecolor",icon:"icon_fontcolor.gif",text:"Font color"},backColor:{cmd:"hilitecolor",icon:"icon_bgcolor.gif",text:"Backrougnd color"},createImage:{cmd:"insertHTML",icon:"icon_img.gif",text:"Insert image link"},header:{cmd:"formatBlock",text:"Set the text format"}},syncContent:function(mode){if(mode=='editor'){this.setHtml(this.getText());}
else{var content=this.getHtml();this.setText(content);}},getHtml:function(){return this.editor.document.body.innerHTML;},setHtml:function(content){this.editor.document.body.innerHTML=content;},setText:function(content){this.isIE()?this.element.val(content):this.element.val(content);},getText:function(){return this.isIE()?this.element.val():this.element.val();},execCmd:function(command,option){if(this.editor){if(option=='removeFormat'){command=option;option=null;}
try{if(this.isIE()&&this.curSelection)
this.curSelection.select();this.editor.document.execCommand(command,false,option);}
catch(e){alert(command+": not supported");}
this.editor.focus();}},fixIEBreak:function(){var self=this;if(this.isIE()){var _doc=$(this.editor.document);_doc.bind("mouseup",function(){if(self.isIE()){if(self.editor.document.selection)
self.curSelection=self.editor.document.selection.createRange();else
self.curSelection=0;}});_doc.bind("keyup",function(event){if(event.keyCode==13){var formmated=self.getHtml().replace(/<P>&nbsp;<\/P>/ig,"").replace(/<P>/ig,"").replace(/<\/P>/ig,"<br/>");self.setHtml(formmated);}});}},runCmd:function(cmd,opt){if(this.isIE()&&!this.curSelection){this.editor.focus();this.curSelection=this.editor.document.selection.createRange();}
if(cmd&&opt){if(cmd=='insertHTML'&&this.isIE())this.curSelection.pasteHTML(opt);else this.execCmd(cmd,opt);}
else if(cmd)this.execCmd(cmd);if(this.isIE())this.curSelection=0;},toggleMode:function(mode){var el=this.element;if(mode=="source"){$(this.rteiFrame).hide();el.show().focus();}
else{el.hide();$(this.rteiFrame).show();this.editor.focus();}
this.syncContent(mode);this.curMode=mode;},buildEditor:function(){var self=this,opts=this.options,el=this.element,rteContainer=$("<div></div>"),_w=(opts.width=="auto"||opts.width=="100%")?"100%":(opts.width+5)+"px";var _strFrame="<iframe src='javascript:void(0);' frameborder='0' style='"+"width:"+_w+";height:"+(opts.height+56)+"px;'></iframe>";rteContainer.appendTo(el.parent()).css({"background-color":opts.bgColor,width:_w}).html(_strFrame);el.appendTo(rteContainer);el.css({width:_w,height:(opts.height+56)+"px","background-color":opts.textBGColor,"border":opts.border});if(self.isIE()){var ieW=(opts.width=="auto"||opts.width=="100%")?"100%":(opts.width+3)+"px";el.css({"overflow":"auto",width:ieW});}
this.rteiFrame=$("iframe",rteContainer)[0];this.rteContainer=rteContainer;},getEditor:function(){var e=false;if(this.isGecko())e=this.rteiFrame.contentWindow;else if(this.isIE())e=this.rteiFrame.contentWindow;if(e&&!this.isDesignModeSupported())e=false;return e;},increaseHeight:function(){this._setHeight(this.element.height()+100);},reduceHeight:function(){if(this.element.height()>120)
this._setHeight(this.element.height()-100);},_setHeight:function(_height){$(this.rteiFrame).css("height",_height);this.element.css("height",_height);},isDesignModeSupported:function(){return(document.designMode&&document.execCommand)?true:false;},isGecko:function(){return(navigator.userAgent.indexOf('Gecko')!=-1)?true:false;},isIE:function(){return $.browser.msie;},initEditor:function(content){var self=this,opts=this.options,el=this.element;if(this.editor=this.getEditor()){var html='<html><head><style> '+'BODY { '+'margin: 4px; '+'background-color: '+opts.textBGColor+'; '+'} '+'BODY, TD, TH { '+'color: black; '+'font-family: '+opts.textFont+'; '+'font-size: '+opts.textFontSize+'px; '+'} '+'TD { border: 1px dashed silver; } '+'P { margin: 0px; } '+'</style></head>'+'<body>'+
content.replace(/<STYLE>[^<]+<\/STYLE>(\r?\n)*/gi,'')+'</body></html>';this.editor.document.designMode='on';if(self.isGecko())this.editor.document.execCommand('useCSS',false,false);this.editor.document.open();this.editor.document.write(html);this.editor.document.close();if(this.setFocus)this.editor.focus();var _form=el.parents("form");if(_form.length){_form.bind("submit",function(){if(self.curMode=="editor")
self.syncContent("source");self.isIE()?el.val(self.htmlEncode(self.getText())):el.text(self.htmlEncode(self.getText()));});}
this.fixIEBreak();}
else alert("Sorry, your browser doesn't support richtext editing!");},encodedHtml:function(){var self=this;if(self.curMode=="editor")
self.syncContent("source");return self.htmlEncode(self.getText());},isHtmlEncode:function(strHtml){if(strHtml.search(/&amp;/g)!=-1||strHtml.search(/&lt;/g)!=-1||strHtml.search(/&gt;/g)!=-1)
return true;else
return false;},htmlEncode:function(strHtml){if(strHtml)
return strHtml.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');else
return"";},htmlDecode:function(strHtml){if(this.isHtmlEncode(strHtml))
return strHtml.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');return strHtml;},insertLink:function(_url,_target){if(_url&&_url!='http://'){if(this.curSelection)
this.runCmd('insertHTML','<a href="'+_url+'" target="'+_target+'">'+this.curSelection.text);else this.runCmd('createLink',_url);}},insertImage:function(_url){if(_url&&_url!='http://'){if(this.curSelection)this.runCmd('insertHTML','<IMG src="'+_url+'">');else this.runCmd('insertImage',_url);}},buildToolbar:function(){var self=this;if(this.rteContainer){this.rteToolbar=$("<ul></ul>").prependTo(this.rteContainer).addClass("ui-helper-reset").css({display:"block",float:"left",margin:"0px",padding:"5px","padding-left":"0px","padding-right":"0px","position":"relative","border-width":"1px","border-color":"#cccccc","border-style":"solid",width:this.rteContainer.width()-2});with(this){buildToolbarButton(this.resource.toggleMode,function(){if(self.mode==undefined){self.mode=self.options.mode;}
if(self.mode=="source"){self.mode="editor";$(".ui-rte-tlb",self.rteToolbar).show();}else{self.mode="source";$(".ui-rte-tlb",self.rteToolbar).hide();}
self.toggleMode(self.mode);}).removeClass("ui-rte-tlb");buildFontNameDropdown(this.resource.fontName);buildFontSizeDropdown(this.resource.fontSize);buildToolbarHeaderFormatButton(this.resource.header);buildToolbarButton(this.resource.bold);buildToolbarButton(this.resource.italic);buildToolbarButton(this.resource.strikeThrough);buildToolbarButton(this.resource.underline);buildColorDropdown(this.resource.fontColor);if(self.isIE())this.resource.backColor.cmd="BackColor";buildColorDropdown(this.resource.backColor);buildToolbarButton(this.resource.justifyLeft);buildToolbarButton(this.resource.justifyCenter);buildToolbarButton(this.resource.justifyRight);buildToolbarButton(this.resource.indent);buildToolbarButton(this.resource.outdent);buildToolbarButton(this.resource.orderList);buildToolbarButton(this.resource.unorderList);buildCreateLinkToolbarButton(this.resource.createLink,function(url){self.insertLink(url,"_blank");});buildCreateLinkToolbarButton(this.resource.createImage,function(url){self.insertImage(url);});};}},buildColorDropdown:function(resObj){var _container=this.createDropdownPanel({width:"231px"}),self=this;var closeDropdown=function(){_container.slideUp().css({"display":"none"}).data("isVisible",false);};_container.appendTo(this.rteToolbar);var palette=this.createColorPalette(function(_color){self.runCmd(resObj.cmd,_color);closeDropdown();});palette.appendTo(_container);var tblBtn=self.buildToolbarButton(resObj,function(){if(_container.data("isVisible")){closeDropdown();}else{_container.css({"left":tblBtn.position().left,"top":(tblBtn.position().top+tblBtn.outerHeight(true))+"px"}).show().data("isVisible",true);}});},buildFontNameDropdown:function(resObj){var fonts=[{name:"arial",text:"Arial"},{name:"comic sans ms",text:"Comic Sans"},{name:"courier new",text:"Courier New"},{name:"georgia",text:"Georgia"},{name:"helvetica",text:"Helvetica"},{name:"impact",text:"Impact"},{name:"times new roman",text:"Times"},{name:"trebuchet ms",text:"Trebuchet"},{name:"verdana",text:"Verdana"}];this.buildDropdownButton({resObj:resObj,data:fonts,onitemCreated:function(item,data,index){item.css({"font-family":data.name});}}).css({"padding-right":"0px"});},buildFontSizeDropdown:function(resObj){var fontsizes=[{name:"1",text:"8pt",size:"8pt"},{name:"1",text:"10pt",size:"10pt"},{name:"2",text:"12pt",size:"12pt"},{name:"3",text:"14pt",size:"14pt"},{name:"4",text:"16pt",size:"16pt"},{name:"5",text:"18pt",size:"18pt"},{name:"6",text:"20pt",size:"20pt"},{name:"7",text:"22pt",size:"22pt"}];this.buildDropdownButton({resObj:resObj,data:fontsizes,width:60,onitemCreated:function(item,data,index){item.css({"font-size":data.size});}}).css({"padding-right":"0px","padding-left":"0px"});},buildDropdownButton:function(_options){var _defaults={selectedIndex:0,data:null,onitemCreated:null,width:90};var _params={};$.extend(_params,_defaults,_options);var self=this;if(this.rteToolbar){var btn=$("<li></li>").appendTo(this.rteToolbar).addClass("ui-helper-reset").addClass("ui-rte-tlb").css({display:"block",float:"left","margin-right":"1px","color":"black",padding:"5px"});var _dropdown=$("<div></div>").appendTo(btn).css({width:_params.width+"px",position:"relative","border-color":"#cccccc","border-width":"1px","border-style":"solid","padding-left":"5px"}).toggle(function(){_dpmenu.show();},function(){_dpmenu.slideUp("fast");})
_dropdown.text(_params.data[_params.selectedIndex].text);_dropdown.append($("<span></span>").css({"background-image":"url("+self.options.imgBaseUrl+"icon_arrow_down.gif)",float:"right",width:"16px",height:"16px"}))
var _dpmenu=this.createDropdownPanel({width:(_params.width+4)+"px",top:"16px"}).appendTo(_dropdown);var itemClick=function(){_dpmenu.slideUp("fast");self.runCmd(_params.resObj.cmd,$(this).attr("cmd"));};$.each(_params.data,function(i,n){var _item=$("<li></li>").appendTo(_dpmenu).attr("cmd",n.name).css({"cursor":"pointer","padding":"5px"}).click(itemClick);_item.text(n.text);if($.isFunction(_params.onitemCreated))_params.onitemCreated(_item,n,i);});return btn;}},createDropdownPanel:function(cssObj){var _panel=$("<ul></ul>").addClass("ui-helper-reset").css({position:"absolute",display:"none",top:"16px",width:"270px",left:"0px","background-color":"white","border-color":"#cccccc","border-width":"1px","border-style":"solid","border-top":"none"});if(cssObj)
_panel.css(cssObj);return _panel;},buildCreateLinkToolbarButton:function(resObj,fn){var self=this,_urlText=$("<input type='text' value='http://' style='width: 220px;' />"),_cbTarget=$("<input type='checkbox' id='richtextbox_dlg_opentarget' />").css({"margin-left":"10px"}),_btnOK=$("<button>OK</button>").css({"margin-left":"10px"}),_viewDlg=this.createDropdownPanel({width:"270px"}).appendTo(this.rteToolbar);$("<li></li>").appendTo(_viewDlg).css({"padding":"5px"}).append($("<lable>URL:</label>").css("color","black")).append(_urlText);$("<li></li>").appendTo(_viewDlg).css({"padding":"5px"}).append(_btnOK.click(function(event){event.preventDefault();if(_urlText.val()&&_urlText.val()!='http://'){if($.isFunction(fn))fn(_urlText.val());}
_viewDlg.slideUp("fast");}));var tblBtn=this.buildToolbarButton(resObj,function(){if(_viewDlg.data("isVisible")){_viewDlg.data("isVisible",false);_viewDlg.slideUp("fast");}
else{_viewDlg.css({"left":tblBtn.position().left,"top":(tblBtn.position().top+tblBtn.outerHeight(true))+"px"}).show();_viewDlg.data("isVisible",true);}});},buildToolbarHeaderFormatButton:function(resObj){var headers=[{name:"<h1>",text:"Header1",html:"<h1>Header1</h1>"},{name:"<h2>",text:"Header2",html:"<h2>Header2</h2>"},{name:"<h3>",text:"Header3",html:"<h3>Header3</h3>"},{name:"<h4>",text:"Header4",html:"<h4>Header4</h4>"},{name:"<h5>",text:"Header5",html:"<h5>Header5</h5>"},{name:"<h6>",text:"Header6",html:"<h6>Header6</h6>"}];this.buildDropdownButton({resObj:resObj,data:headers,onitemCreated:function(item,data,index){item.html(data.html);}});},createColorPalette:function(selectedCallback){var colors=["#FFFFFF","#FFCCCC","#FFCC99","#FFFF99","#FFFFCC","#99FF99","#99FFFF","#CCFFFF","#CCCCFF","#FFCCFF","#CCCCCC","#FF6666","#FF9966","#FFFF66","#FFFF33","#66FF99","#33FFFF","#66FFFF","#9999FF","#FF99FF","#C0C0C0","#FF0000","#FF9900","#FFCC66","#FFFF00","#33FF33","#66CCCC","#33CCFF","#6666CC","#CC66CC","#999999","#CC0000","#FF6600","#FFCC33","#FFCC00","#33CC00","#00CCCC","#3366FF","#6633FF","#CC33CC","#666666","#990000","#CC6600","#CC9933","#999900","#009900","#339999","#3333FF","#6600CC","#993399","#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366","#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033"];var palette=$("<table border='0' cellpadding='1' cellspacing='1'></table>");var curRow=$("<tr></tr>").appendTo(palette);var count=0;$.each(colors,function(i,n){$("<td></td>").appendTo(curRow).css({"background-color":n,width:"20px",height:"20px"}).append($("<img />").css({width:"1px",height:"1px"})).click(function(){selectedCallback(n);});count++;if(i<70){if(count%10==0){curRow=$("<tr></tr>").appendTo(palette);}}});return palette;},buildStatusBar:function(){if(this.rteContainer){var self=this,_status=$("<ul></ul>").appendTo(this.rteContainer).addClass("ui-helper-reset").css({display:"block",float:"left",margin:"0px",padding:"5px","padding-left":"0px","padding-right":"0px","position":"relative","border-width":"1px","border-color":"#cccccc","border-style":"solid",width:this.rteContainer.width()-2});this.rteStatusBar=_status;return _status;}},buildToolbarButton:function(resObj,fn){var self=this,_fullUrl=this.options.imgBaseUrl+resObj.icon;var _buttonClick=function(){self.runCmd(resObj.cmd);};if($.isFunction(fn))
_buttonClick=fn;if(this.rteToolbar){var hoverCss={"border-width":"1px","border-color":"#cccccc","border-style":"solid"},defaultCss={"border-width":"1px","border-color":"#FFFFFF","border-style":"solid"};return $("<li></li>").appendTo(this.rteToolbar).addClass("ui-helper-reset").addClass("ui-rte-tlb").css({display:"block",float:"left","margin-right":"1px",padding:"5px","border-width":"1px","border-color":"#FFFFFF","border-style":"solid"}).hover(function(){$(this).css(hoverCss);},function(){$(this).css(defaultCss);}).append($("<img/>").attr("src",_fullUrl).attr("title",resObj.text).css({float:"left",cursor:"pointer",height:"16px",width:"16px"}).bind("click",_buttonClick));}}});$.widget("ui.splitter",{options:{paneA:null,paneB:null,autoSize:true,minWidth:250,fillSpace:true},_create:function(){var self=this,opts=this.options,el=this.element,paneA=$(opts.paneA),paneB=$(opts.paneB),_rect={width:el.parent().width(),height:el.parent().height()};if(opts.autoSize){el.css({"min-width":_rect.width+"px","min-height":_rect.height+"px"});}
var _widthA=0;paneA.resizable({handles:"e",ghost:true,helper:"ui-state-highlight",minWidth:opts.minWidth,"height":_rect.height+"px",stop:function(event,ui){_widthA=paneA.outerWidth(true);paneB.css({"width":((_rect.width-_widthA)-15)+"px"})}});paneA.css({"float":"left","padding":"2px","margin-right":"3px","height":_rect.height+"px","width":opts.minWidth+"px"});_widthA=paneA.outerWidth(true);if(opts.fillSpace){var _children=$(":first",paneA);if(_children){_children.css({"overflow":"auto","height":(_rect.height-4)+"px"});}}
paneB.css({"float":"left","height":_rect.height+"px","width":((_rect.width-_widthA)-15)+"px","padding":"2px"});_handler=$(".ui-resizable-handle",paneA);_handler.bind("dblclick",function(){if(paneA.width()==1){paneA.css({"width":_widthA+"px"});paneB.css({"width":((_rect.width-_widthA)-23)+"px"});}
else{paneA.width(1);paneB.css({"width":(_rect.width-23)+"px"});}});},destroy:function(){$.Widget.prototype.destroy.call(this);}});$.widget("ui.stylebuilder",{options:{targetElement:null,valueContainer:null,className:null,uploadUrl:null},_create:function(){var self=this,el=this.element;el.html(this._html);this.objectPool=[];this.bgcolorVal=$("#bgcolor_picker");this.bordercolorVal=$("#bordercolor_picker");this.fontcolorVal=$("#fontcolor_picker");this.opacityVal=$("#opacityVal")
this.widthVal=$("#widthVal");this.heighVal=$("#heighVal");this.fontSizeVal=$("#fontSizeVal");this.familyVal=$("#familyVal");this.norepeatradio=$("#bg_norepeat");this.repeatradio=$("#bg_repeat");this.xrepeatradio=$("#bg_repeatx");this.yrepeatradio=$("#bg_repeaty");this.bgalignleftradio=$("#bg_align_l")
this.bgaligncenterradio=$("#bg_align_c")
this.bgalignrightradio=$("#bg_align_r")
this.showbordercheck=$("#showborder_checkbox");this.textalignleftradio=$("#textalign_left");this.textaligncenterradio=$("#textalign_center");this.textalignrightradio=$("#textalign_right");this.fontnormaltradio=$("#weight_normal");this.fontboldradio=$("#weight_bold");this.btndowndrop=$("#btndowndrop");this.load();this.objectPool.push(this._createColorPicker("bgcolor_picker"));this.objectPool.push(this._createColorPicker("bordercolor_picker"));this.objectPool.push(this._createColorPicker("fontcolor_picker"));var _roller=this._createOpacityRoller(this.opacityVal);with(this){bgcolorVal.change(function(){self._change["background-color"]=self._getColor($(this).val());self.save();});bordercolorVal.change(function(){self._change["border-color"]=self._getColor($(this).val());self.save();});fontcolorVal.change(function(){self._change["color"]=self._getColor($(this).val());self.save();});familyVal.change(function(){self._change["font-family"]=$(this).val();self.save();});widthVal.change(function(){var vw=$(this).val();if(!vw)vw="auto";self._change["width"]=vw;self.save();});heighVal.change(function(){var vh=$(this).val();if(!vh)vw="auto";self._change["height"]=$(this).val();self.save();});opacityVal.change(function(){var ov=$(this).val();if(ov=="")return;self._change["opacity"]=ov/100;self.save();});fontSizeVal.change(function(){if($(this).val())self._change["font-size"]=$(this).val();self.save();});textalignleftradio.click(function(){self._change["text-align"]="left";self.save();});textaligncenterradio.click(function(){self._change["text-align"]="center";self.save();});textalignrightradio.click(function(){self._change["text-align"]="right";self.save();});fontnormaltradio.click(function(){self._change["font-weight"]="normal";self.save();});fontboldradio.click(function(){self._change["font-weight"]="bold";self.save();});bgalignleftradio.click(function(){self._change["background-position-y"]="top";self.save();});bgaligncenterradio.click(function(){self._change["background-position-y"]="center";self.save();});bgalignrightradio.click(function(){self._change["background-position-y"]="bottom";self.save();});norepeatradio.click(function(){self._change["background-repeat"]="no-repeat";self.save();});repeatradio.click(function(){self._change["background-repeat"]="repeat";self.save();});xrepeatradio.click(function(){self._change["background-repeat"]="repeat-x";self.save();});yrepeatradio.click(function(){self._change["background-repeat"]="repeat-y";self.save();});showbordercheck.bind("click",function(){if($(this).attr("checked")){self._change["border-style"]="solid";self._change["border-width"]=1;self._change["border-color"]=bgcolorVal.val();bordercolorVal.attr("disabled",false);}
else{self._change["border-style"]="none";self._change["border-width"]=0;self._change["border-color"]="transparent";bordercolorVal.attr("disabled",true);}
self.save();});};var _box=this._createLinkbox(this.btndowndrop);this.btndowndrop.css({"width":"20px","height":"20px","margin-right":"5px","margin-left":"5px"}).click(function(event){event.preventDefault();_box.position({of:self.btndowndrop,my:"left top",at:"left bottom"}).slideToggle();}).button({text:false,icons:{primary:'ui-icon ui-icon-carat-1-s'}});},_change:{},hasChange:function(){for(var c in this._change)
return true;return false;},_createLinkbox:function(el){var self=this,box=$("<ul></ul>").addClass("ui-helper-reset ui-widget-content").appendTo("body").css({position:"absolute",padding:"5px"}),_urlText=$("<input type='text' value='http://' style='width: 220px;margin-left:3px;' />"),_btnOK=$("<button>OK</button>").css({"margin-left":"10px"}).click(function(event){event.preventDefault();var _url=_urlText.val();if(_url&&_url!="http://")
self._change["background-image"]="url('"+_url+"')";else
self._change["background-image"]="none";box.slideToggle();self.save();}).button(),_btnUpload=$("<button>Upload</button>").css({"margin-left":"5px"}).button(),_uploader=new AjaxUpload(_btnUpload,{action:self.options.uploadUrl,name:"UploadFile",responseType:'json',onChange:function(){if(uiHelper)
uiHelper.blockUI(box);_uploader.disable();},onComplete:function(file,state){if(uiHelper)
uiHelper.unblockUI(_box);_uploader.enable();if(state.successful){if(state){if(state.fileName)
_urlText=state.fileName;}}
else{if(uiHelper)
uiHelper.showMsg(portal.res.Error,state.responseText);}}});var _te=this.options.targetElement
if(_te){var imgUrl=_te.css("background-image");if(imgUrl){_urlText.val(this._getbackgroundUrl(imgUrl));}}
$("<li></li>").appendTo(box).css({"padding":"5px"}).append($("<lable>URL:</label>").css("color","black")).append(_urlText);$("<li></li>").appendTo(box).append(_btnOK).append(_btnUpload);_urlText.textbox();box.position({of:el,my:"left top",at:"left bottom"}).hide();this.bgImageUrlVal=_urlText;this.objectPool.push(box);this.uploader=_uploader;return box;},_getbackgroundUrl:function(value){if(value){var _formattedUrl=value;if(value.substring(0,4).toLowerCase()=="url("){_formattedUrl=value.substring(4,value.length-1);if((_formattedUrl.substring(0,1)=="\"")||(_formattedUrl.substring(0,1)=="'"))
_formattedUrl=_formattedUrl.substring(1,value.length-2);}
return _formattedUrl;}},_html:"<div class='fieldgroup'><label for='bgcolor_picker'>Background color & opacity</label>"+"<div><input size=\"7\" type='text' value=\"#000000\" id=\"bgcolor_picker\" class=\"inputbox ui-corner-all\" /><button id='btndowndrop'/><input size=\"3\" value=\"20\" id='opacityVal' class=\"inputbox ui-corner-all\" /><span>%</span></div></div>"+"<div class=\"fieldgroup\"><label for=\"bgcolor_picker\">Background repeat</label><div>"+"<input type=\"radio\" id=\"bg_norepeat\" name='bgrepeat' /><label for=\"bg_norepeat\">no</label>"+"<input type=\"radio\" id=\"bg_repeat\" checked=\"checked\"  name='bgrepeat' /><label for=\"bg_repeat\">repeat</label>"+"<input type=\"radio\" id=\"bg_repeatx\"  name='bgrepeat' /><label for=\"bg_repeatx\">x</label>"+"<input type=\"radio\" id=\"bg_repeaty\"  name='bgrepeat' /><label for=\"bg_repeaty\">y</label>"+"</div></div><div class=\"fieldgroup\"><label for=\"bgcolor_picker\">Background position</label><div>"+"<div>"+"<input type=\"radio\" id=\"bg_align_l\" name='bgalign' checked=\"checked\" /><label for=\"bg_align_l\">left</label>"+"<input type=\"radio\" id=\"bg_align_c\"  name='bgalign' /><label for=\"bg_align_c\">center</label>"+"<input type=\"radio\" id=\"bg_align_r\"  name='bgalign' /><label for=\"bg_align_r\">right</label>"+"</div></div></div>"+"<div class=\"fieldgroup\">"+"<input type=\"checkbox\" id=\"showborder_checkbox\"/>"+"<label for=\"showborder_checkbox\">Show border</label><input value=\"#000000\" size=\"7\" id=\"bordercolor_picker\" class=\"inputbox ui-corner-all colorpicker\" /></div>"+"<div class=\"fieldgroup\"><div class=\"field\"><label for=\"widthVal\">Width</label>"+"<input value=\"200\" size=\"7\" id=\"widthVal\" type='text'  class=\"inputbox ui-corner-all\" /></div>"+"<div class=\"field\"><label for=\"heighVal\">Height</label>"+"<input value=\"100\" size=\"7\" id=\"heighVal\" type='text' class=\"inputbox ui-corner-all\" /></div></div>"+"<div class=\"fieldgroup\"><div style=\"float: left; width: 100px;\"><label for=\"familyVal\">Family</label>"+"<input value=\"Arial,sans-serif\" size=\"18\" id=\"familyVal\" class=\"inputbox ui-corner-all\" /></div></div>"+"<div class=\"fieldgroup\"><div> <div class=\"field\">  <label for=\"fontSizeVal\">Size</label><input value=\"9\" type='text' size=\"6\" id=\"fontSizeVal\" class=\"inputbox ui-corner-all\" /></div>"+"<div class=\"field\"><label for=\"fontcolor_picker\">Color</label><input value=\"#000000\" size=\"7\" id=\"fontcolor_picker\" class=\"inputbox ui-corner-all colorpicker\" /></div></div></div>"+"<div class=\"fieldgroup\"><label for=\"weight_normal\">Weight</label><input type=\"radio\" id=\"weight_normal\" checked=\"checked\" name='fontweight' /><label for=\"weight_normal\">normal</label><input type=\"radio\" id=\"weight_bold\" name='fontweight' /><label for=\"weight_bold\">bold</label></div>"+"<div class=\"fieldgroup\"><label for=\"textalign_left\">Align</label><input type=\"radio\" checked=\"checked\" id=\"textalign_left\" name=\"txtalign\" /><label for=\"textalign_left\">left</label>"+"<input type=\"radio\" id=\"textalign_center\" name=\"txtalign\" /><label for=\"textalign_center\">center</label><input type=\"radio\" id=\"textalign_right\" name=\"txtalign\" /><label for=\"textalign_right\">right</label></div>",_getColor:function(_color){if(_color){if(_color.substring(0,4)=="rgba")return this.rgbaToHex(_color);if(_color.substring(0,3)=="rgb")return this.rgbToHex(_color);return _color;}
else
return"transparent";},rgbaToHex:function(str){str=str.replace(/rgba\(|\)/g,"").split(",");str[0]=parseInt(str[0],10).toString(16).toLowerCase();str[1]=parseInt(str[1],10).toString(16).toLowerCase();str[2]=parseInt(str[2],10).toString(16).toLowerCase();str[0]=(str[0].length==1)?'0'+str[0]:str[0];str[1]=(str[1].length==1)?'0'+str[1]:str[1];str[2]=(str[2].length==1)?'0'+str[2]:str[2];return('#'+str[0]+str[1]+str[2]);},rgbToHex:function(str){str=str.replace(/rgb\(|\)/g,"").split(",");str[0]=parseInt(str[0],10).toString(16).toLowerCase();str[1]=parseInt(str[1],10).toString(16).toLowerCase();str[2]=parseInt(str[2],10).toString(16).toLowerCase();str[0]=(str[0].length==1)?'0'+str[0]:str[0];str[1]=(str[1].length==1)?'0'+str[1]:str[1];str[2]=(str[2].length==1)?'0'+str[2]:str[2];return('#'+str.join(""));},load:function(){var target=this.options.targetElement;if(target){var _bc=this._getColor(target.css("background-color").toLowerCase());if(_bc=="transparent"){this.bgcolorVal.val("#ffffff");this.opacityVal.val(0);}
else{this.bgcolorVal.val(_bc);this.opacityVal.val(target.css("opacity")*100);}
this.bgcolorVal.css("background-color",_bc);var bstyle=$.browser.mozilla==true?target.css("border-left-style").toLowerCase():target.css("border-style").toLowerCase();if(bstyle==""||bstyle=="none"||bstyle=="hidden"){this.showbordercheck.attr("checked",false);this.bordercolorVal.attr("disabled",true);}
else{this.bordercolorVal.attr("disabled",false);var _brcolor="";if($.browser.mozilla)
_brcolor=this._getColor(target.css("border-left-color"));else
_brcolor=this._getColor(target.css("border-color"));this.bordercolorVal.val(_brcolor);this.bordercolorVal.css("background-color",_brcolor);this.showbordercheck.attr("checked",true);}
var fcolor=this._getColor(target.css("color"));this.fontcolorVal.val(fcolor);this.fontcolorVal.css("background-color",fcolor);this.fontSizeVal.val(target.css("font-size"));if(this._getFontWeight(target.css("font-weight"))=="normal")
this.fontnormaltradio.attr("checked",true);else
this.fontboldradio.attr("checked",true);if(target.css("text-align").toLowerCase()=="left")this.textalignleftradio.attr("checked",true);if(target.css("text-align").toLowerCase()=="center")this.textaligncenterradio.attr("checked",true);if(target.css("text-align").toLowerCase()=="right")this.textalignrightradio.attr("checked",true);if(this._getBGPosition(target)=="left")this.bgalignleftradio.attr("checked",true);if(this._getBGPosition(target)=="center")this.bgaligncenterradio.attr("checked",true);if(this._getBGPosition(target)=="right")this.bgalignrightradio.attr("checked",true);if(target.css("background-repeat").toLowerCase()=="no-repeat")this.norepeatradio.attr("checked",true);if(target.css("background-repeat").toLowerCase()=="repeat")this.repeatradio.attr("checked",true);if(target.css("background-repeat").toLowerCase()=="repeat-x")this.xrepeatradio.attr("checked",true);if(target.css("background-repeat").toLowerCase()=="repeat-y")this.yrepeatradio.attr("checked",true);this.familyVal.val(target.css("font-family"));this.heighVal.val(target.css("height"));this.widthVal.val(target.css("width"));var _bgImgUrl=target.css("background-image");if(this.bgImageUrlVal)
this.bgImageUrlVal.val(this._getbackgroundUrl(_bgImgUrl));this._change={};}},_getBGPosition:function(el){var _x=el.css("background-position-x"),_y=el.css("background-position-y");if(_y=="0px")return"left"
return _y;},_getFontWeight:function(value){if(typeof(value)=="number"){if(value<=400)return"normal";if(value>=700)return"bold";}
else{return value.toLowerCase();}},undo:function(){if(this.options.targetElement){this.options.targetElement.removeAttr("style");this.load();if(this.options.valueContainer){this.options.valueContainer.val("");}}},save:function(){var target=this.options.targetElement;if(target&&this.hasChange()){target.css(this._change);if(this.options.valueContainer){this.options.valueContainer.val(this.toStyleString());}}},toStyleString:function(){var _result="";for(var a in this._change){if(this._change[a])
_result+=a.toString()+":"+this._change[a].toString()+"!important;";}
if(this.options.className)
_result=this.options.className+"{"+_result+"}";return _result;},_createRadio:function(_id,txt,_value,fn){return $("<input type='hidden' id='"+_id+"' name='"+_id+"'/>").radio({text:txt,value:_value!=undefined?"ture":"false",change:fn});},_createOpacityRoller:function(el){var self=this;var _container=$("<div />").appendTo("body").css({"width":"100px","position":"absolute"}).addClass("ui-widget-content");_container.position({of:el,my:"left top",at:"left bottom"}).hide();var _slider=$("<div/>").appendTo(_container).slider({value:el.val()!=""?el.val():0,min:0,max:100,step:1,slide:function(event,ui){el.val(ui.value);},stop:function(){_container.hide();el.trigger("change");}});el.focus(function(){_container.show().position({of:$(this),my:"left top",at:"left bottom"});});this.objectPool.push(_container);return _slider;},_createColorPicker:function(_id){var pId=_id+"_picker",_tg=$("#"+_id);if(_tg){var _picker=$("<div id='"+pId+"'></div>").appendTo("body").addClass("farbtastic ui-widget-content ui-corner-all").css({"position":"absolute"}).farbtastic("#"+_id);_picker.position({of:_tg,my:"left top",at:"left bottom"}).hide();_tg.focus(function(){$("#"+$(this).attr("id")+"_picker").show().position({of:$(this),my:"left top",at:"left bottom"});}).blur(function(){_picker.hide();_tg.trigger("change")});return _picker;}},destroy:function(){var len=this.objectPool.length;for(var i=0;i<len;i++){this.objectPool.pop().remove();}
if(this.uploader)
this.uploader.destroy();this.element.children().unbind();this.element.html("");$.Widget.prototype.destroy.call(this);}});$.widget("ui.tags",{options:{event:"click",pos:"left",selectedIndex:0,select:null,show:null},_create:function(){var self=this,opts=this.options,el=this.element,layout=opts.pos,_parent=el.parent(),_table=$("<table></table>").appendTo(el).attr("cellpadding","0").attr("cellspacing","0").css({"width":"100%"}),_tr=$("<tr></tr>").appendTo(_table),_leftCol=$("<td></td>").appendTo(_tr).attr("valign","top"),_rightCol=$("<td></td>").appendTo(_tr).attr("valign","top");if((layout!="left")&&(layout!="right"))
layout="left";el.addClass("ui-corner-all ui-widget-header").css({"padding":"5px","background-position":"0 0"});if(opts.select)
el.bind("tagselect",opts.select);if(opts.show)
el.bind("tagshow",opts.show);var ul=el.find("ul:first"),_panels=$(">div",el);if(ul.length>0){if(layout=="left"){ul.appendTo(_leftCol);if(_panels.length)_panels.appendTo(_rightCol);_leftCol.css({"white-space":"nowrap","width":"80px"});}
else{ul.appendTo(_rightCol);if(_panels.length)_panels.appendTo(_leftCol);_rightCol.css({"white-space":"nowrap","width":"80px"});}
ul.addClass("ui-helper-reset").addClass("ui-tags-nav").css({"display":"block"});ul.children("li").each(function(i,n){var $I=$(this);if(layout=="left")
$I.addClass("ui-state-default ui-corner-left").css({"height":"30px","border-right":"none"});else
$I.addClass("ui-state-default ui-corner-right").css({"height":"30px","border-left":"none"});$I.hover(function(){$(this).addClass("ui-state-hover");},function(){$(this).removeClass("ui-state-hover");});$I.find("a:first").bind(opts.event,function(){self.selectTag($(this).parent());el.trigger("tagselect",{index:i,tag:$(this).parent(),panel:$($(this).attr("href"))});return false;});if(i==0)
$I.css({"margin-top":"0px"});else
$I.css({"margin-top":"2px"});if(i==opts.selectedIndex)
$I.addClass("ui-state-active").addClass("ui-state-focus")
var _link=$("a",this);_link.css({"display":"inline-block","padding":"6px"});var _container=$(_link.attr("href"));if(_container.length>0){_container.wrap("<div></div>");var _corner="ui-widget-content ui-corner-left";if(layout=="left")
_corner="ui-widget-content ui-corner-right";_container.addClass(_corner).css({"padding":"5px"});_container.parent().addClass(_corner).addClass("ui-state-active").css({"padding":"5px","background-position":"0 0","display":"none","overflow":"auto"});_container.css({"overflow":"auto"});if(layout=="left")
_container.parent().css({"border-left":"none"});else
_container.parent().css({"border-right":"none"});if(i==opts.selectedIndex)
_container.parent().show();}});}},setIndex:function(value){if(this.options.selectedIndex!=value){this.selectTag($(">table>tr>td>ul>li",this.element).get(value));}},selectTag:function(el){var self=this,opts=this.options,$tag=$(el),_panel=$($("a",el).attr("href"));$(">table>tbody>tr>td>ul>li",self.element).removeClass("ui-state-active").removeClass("ui-state-focus");$(el).addClass("ui-state-active").addClass("ui-state-focus");$(">div",_panel.parent().parent()).hide();_panel.parent().show();opts.selectedIndex=$(">table>tbody>tr>td>ul>li",self.element).index(el);this.element.trigger("tagshow",{index:opts.selectedIndex,tag:$tag,panel:_panel});},remove:function(value){var self=this,opts=this.options,el=this.element,_tag=$(">ul>li",el).get(value),_panel=$($("a",_tag).attr("href"));$(_tag).unbind();$(_tag).remove();_panel.remove();}});$.widget("ui.textbox",{options:{value:"",multiline:false,clearable:true,changed:null,waterMark:null,waterMarkClass:"",width:200,height:23,clearText:"Clear the input text.",iconClass:null,textClass:"ui-input ui-state-default",activeClass:"ui-state-active",cssClass:"ui-textbox ui-corner-all ui-state-default",highlightClass:"ui-state-highlight"},_create:function(){var self=this,opts=this.options,el=this.element;el.wrap("<div></div>");var w=opts.width,_com=el.parent();this.container=_com;if(opts.cssClass)
_com.addClass(opts.cssClass);if(opts.textClass){el.addClass(opts.textClass);}
if(opts.value)
el.val(opts.value);if(opts.changed)
el.bind("textchange",opts.changed);el.css("width",opts.width+"px");_com.width(opts.width);if(opts.iconClass){var _ico=$("<span></span>");_ico.addClass(opts.iconClass);_com.prepend(_ico);el.css({"padding-left":"18px"});if(el.attr("title")){self.title=el.attr("title");_ico.attr("title",self.title);el.attr("title","");if($.fn.tooltip){_ico.tooltip({delay:0});}}
_ico.css({"position":"absolute","float":"left","margin-top":"-8px","margin-right":"5px","margin-left":"5px","left":"0","top":"50%"});_ico.click(function(){el.focus();});w-=16;}
if(opts.waterMark)
el.watermark({waterMark:opts.waterMark,waterMarkClass:opts.waterMarkClass});if(opts.clearable){el.css({"padding-right":"16px"});w-=16;var _clr=$("<span class='ui-icon ui-icon-close'></span>");if(opts.clearText){_clr.attr("title",opts.clearText);if($.fn.tooltip)
_clr.tooltip({delay:0});}
_clr.css({"position":"absolute","float":"right","margin-top":"-8px","margin-right":"5px","right":"0","left":"auto","top":"50%"});el.css("width",w+"px");_com.append(_clr);if(el.val()=="")
_clr.hide();_clr.bind("click",function(){el.val("");_clr.hide();el.focus();});el.bind("change",function(){if(el.val()!="")
_clr.show();else
_clr.hide();opts.value=el.val();el.trigger("textchange",opts.value);});}
if(opts.highlightClass){el.hover(function(){$(this).parent().addClass(opts.highlightClass);$(this).addClass(opts.highlightClass);},function(){$(this).removeClass(opts.highlightClass);$(this).parent().removeClass(opts.highlightClass);});}
el.bind("focus",function(){if(opts.activeClass){$(this).addClass(opts.activeClass);$(this).parent().addClass(opts.activeClass);}});el.bind("blur",function(){if(opts.activeClass){$(this).parent().removeClass(opts.activeClass);$(this).removeClass(opts.activeClass);}});}});$.widget("ui.toolbar",{options:{parentToolbar:null,itemHoverClass:"ui-state-hover",itemSelectedClass:"ui-state-active",itemClass:null,commands:null,name:null},_create:function(){var self=this,opts=this.options,el=this.element;el.css({"display":"block","overflow":"auto"});if(opts.sortable){if($.fn.sortable){el.sortable({connectWith:opts.items,placeholder:"ui-state-highlight",forceHelperSize:true,forcePlaceholderSize:true,forceHelperSize:true,revert:true,opacity:0.8,helper:"clone",cursor:"move",items:">ul"});}}
$.each(opts.toolpanes,function(i,n){this.itemHoverClass=opts.itemHoverClass;this.itemClass=opts.itemClass;this.parentToolbar=self;var p=$("<ul></ul>").appendTo(el).toolpane(this);p.bind("toolbarbuttoncommand",function(event,cmd){el.trigger("toolbarcommand",cmd);});});if(el.height()){el.height(el.height());el.css({"overflow":""});}
if(opts.command)
this.element.bind("toolbarcommand",opts.command);},getPanes:function(){return $(">ul",this.element);},getCommand:function(strID){var _cmd=$("li[cmdID='"+strID+"']",this.element);if(_cmd.length)
return _cmd;else
return false;}});$.extend($.ui.toolbar,{defaults:{toolpanes:null,sortable:true,itemHoverClass:"ui-state-hover",itemClass:null,command:null}});$.widget("ui.toolpane",{_init:function(){var self=this,opts=this.options,el=this.element;el.addClass("ui-helper-reset ui-state-default ui-corner-all").css({"float":"left","display":"block","margin":"1px","padding":"2px","padding-left":"0px"});$("<li></li>").appendTo(this.element).addClass("ui-helper-reset").css({"float":"left","margin-right":"1px","padding-top":"5px","padding-left":"0px","display":"block","cursor":"move"}).append($("<span></span>").addClass("ui-icon ui-icon-grip-dotted-vertical").css({"width":"10px"}));if(opts.commands){for(var i=0;i<opts.commands.length;i++){self.add(opts.commands[i]);}}},items:function(){return $(">li",this.element)},createbutton:function(o){var self=this,item=$("<span></span>").addClass(o.icon).css({"cursor":"pointer"});if(o.text)
item.attr("title",o.text);if(o.exec)
item.bind("click",o.exec);item.bind("click",function(){self.element.trigger("toolbarbuttoncommand",o);});return item;},createtextbutton:function(o){var self=this,item=$("<a></a>").css({"display":"inline-block"});item.attr("href","javascript:void(0);");item.text(o.text);$("<span></span>").prependTo(item).addClass(o.icon).css({"float":"left"});if(o.exec)
item.bind("click",o.exec);item.bind("click",function(){self.element.trigger("toolbarbuttoncommand",o);});return item;},createdropdown:function(o){var self=this,item=$("<div></div>");var dd=$("<ul></ul>").appendTo(item);if(o.data){for(var i=0;i<o.data.length;i++){$("<li></li>").appendTo(dd).append("<a>"+o.data[i].text+"</a>").end().append("<input type='hidden' value='"+o.data[i].value+"'/>");}}
var w=100;if(o.width)
w=o.width;item.dropdown({defaultText:o.text,height:20,width:w});if(o.exec)
item.bind("selectedChanged",o.exec);item.bind("selectedChanged",function(event,ui){o.args=ui;self.element.trigger("toolbarbuttoncommand",o);});item.css({"margin":"0px","padding":"0px","margin-top":"2px"});item.disableParent=true;return item;},createtext:function(o){var item=$("<label></label>");if(o.text)
item.text(o.text);item.disableParent=true;return item;},createspliter:function(o){var item=$("<span></span>").addClass("ui-widget-content").css({"border-top":"none","border-left":"none","border-bottom":"none","background":"none",width:2});item.disableParent=true;return item;},add:function(cmd){var opts=this.options;if(cmd.type==undefined)
cmd.type="button";if(this["create"+cmd.type]){var command=this["create"+cmd.type](cmd);var tbItem=$("<li></li>").appendTo(this.element).addClass("ui-helper-reset").css({"float":"left","padding":"5px","font-weight":"normal","margin-right":"1px","display":"block","border":"none"}).append(command);if(cmd.id){tbItem.attr("cmdID",cmd.id);}
if(cmd.type=="dropdown")
tbItem.css({"padding":"0px"});if(command.disableParent){return tbItem;}
else{if(opts.itemClass)
tbItem.addClass(opts.itemClass);if(cmd.checkable)
var _class=opts.itemSelectedClass;tbItem.bind("click",function(){if($(this).hasClass(_class))
$(this).removeClass(_class);else
$(this).addClass(_class);});tbItem.hover(function(){$(this).addClass(opts.itemHoverClass);},function(){$(this).removeClass(opts.itemHoverClass);});}}}});$.widget("ui.treenode",{options:{tree:null,baseImageUrl:"/content/images/treeview/"},_create:function(){var el=this.element,eventPrefix=this.widgetEventPrefix,self=this;el.addClass("ui-helper-reset").addClass("dna-treeview-node").css({"clear":"left","min-height":"20px","margin":"0px"});el.wrapInner("<div class='dna-treeview-node-content' style='padding-top:2px;height:19px;'></div>");var _child=el.children(".dna-treeview-node-content").children("ul");if(_child.length)el.append(_child);el.prepend(this._createToggleButton());this.contentElement=el.children(".dna-treeview-node-content");this.contentElement.disableSelection();this.contentElement.click(function(event){event.stopPropagation();if(self.options.tree)
self.options.tree._onselect(self);});},select:function(){if(this.options.tree)
this.options.tree._onselect(this);},contentElement:null,toggleButton:null,_createToggleButton:function(){var _tbtn=$("<div/>").addClass("dna-treeview-node-togglebutton").css({float:"left",width:"19px",height:"20px","background-repeat":"no-repeat"}),self=this;if(this.hasChildren()&&this.isCollapsed())
this._getChildHolder().hide();_tbtn.click(function(){self.toggle();});this.toggleButton=_tbtn;this.refresh();return _tbtn;},del:function(){if(this.element.parent().length==0){this.element.remove();return;}
var _pe=this.element.parent().parent();this.element.remove();_pe.treenode("refresh");var _children=_pe.find(".dna-treeview-node");if(_children.length){_children.treenode("refresh");}
_pe.children(".dna-treeview-node-content").click();},refresh:function(){var _img="dash";this.element.removeClass("dna-treeview-node-expanded");if(this.hasChildren()){if(this.isCollapsed()){_img=this.isLast()?"lplus":"dashplus";}
else{_img=this.isLast()?"lminus":"dashminus";this.element.addClass("dna-treeview-node-expanded");}}
else{if(this.isLast())
_img="l";}
if(this.isLast())
this.element.css("background","none");else{this.element.css({"background-image":"url("+this.options.baseImageUrl+"i.gif)","background-repeat":"repeat-y"});}
this.toggleButton.css("background-image","url("+this.options.baseImageUrl+_img+".gif)");},toggle:function(){var self=this;if(this.hasChildren()){var _toggleCore=function(_effect){self._getChildHolder().toggle(_effect,{},500,function(){self.refresh();});}
var _showCore=function(_effect){self._getChildHolder().show(_effect,{},500,function(){self.refresh();});}
if(this.isCollapsed()){if(this.element.attr("src")){$.ajax({url:this.element.attr("src"),type:"PLIST",success:function(html){self.element.removeAttr("src");self.add(html);self.element.attr("collapsed","false");_showCore("blind");}});}
else{this.element.attr("collapsed","false");}}else{this.element.attr("collapsed","true");}
_toggleCore("blind");}},_getChildHolder:function(){return this.element.children("ul");},isCollapsed:function(){if(this.element.attr("collapsed")==undefined)return false;else
if(this.element.attr("collapsed")=="true")
return true;else return false;},isLast:function(){return this.element.next().length?false:true;},hasChildren:function(){if(this.element.attr("src")){if(this.element.attr("collapsed")==undefined)this.element.attr("collapsed","true");return true;}
return this._getChildHolder().length==0?false:true;},add:function(nodes){if(nodes){if(nodes.length){var _ns=$(nodes);if(_ns.get(0).tagName=="UL")
_ns=$(nodes).children();if(_ns.length){if(this.hasChildren()){this._getChildHolder().append(_ns);}else{var _holder=$("<ul/>");_holder.append(_ns).addClass("ui-helper-reset").css({"padding-left":"5px","margin-left":"20px"});this.element.append(_holder);}
this.options.tree._initNodes(_ns);this.options.tree._initNodeHolder(_ns);this.refresh();this._getChildHolder().find("li").treenode("refresh");}
else this.refresh();}}},destroy:function(){$.Widget.prototype.destroy.call(this);}});$.widget("ui.treeview",{options:{baseImageUrl:"/content/images/treeview/",url:null,httpMethod:"GET",beforeNodeLoad:null,enableDropAndDrag:false,disableLinks:false,select:null,dropped:null,selectedKey:null,selectedNode:null,selectedClass:null,defaultClass:null,applyClassTo:null},_create:function(){var eventPrefix=this.widgetEventPrefix,self=this;if(this.options.url){$.ajax({url:this.options.url,type:this.options.httpMethod,success:function(_html){if(_html){self.element.html(_html);self._initNodeHolder(self.element);self._initNodes(self.element.find("li"));if(self.element[0].tagName!="UL")
$(">ul",self.element).css({"margin-left":"0px","padding-left":"0px"});}}});}else{this._initNodeHolder(this.element);this._initNodes(this.element.find("li"));}
if(this.options.select){this.element.bind(eventPrefix+"select",this.options.select);}
if(this.options.dropped){this.element.bind(eventPrefix+"dropped",this.options.dropped);}
if(this.options.disableLinks){this.element.find("a").each(function(i,n){var _h=$(n).attr("href");$(n).attr("href","javascript:void(0);").attr("rel",_h);});}
if(this.options.selectedKey)
this.selectNodeByKey(this.options.selectedKey);},_onselect:function(n){var opts=this.options;opts.selectedNode=n;if(opts.applyClassTo){if(opts.selectedClass){var sel=this.element.find("."+opts.selectedClass);if(sel.length)sel.removeClass(opts.selectedClass);var _el=$(">.dna-treeview-node-content",n.element).find(opts.applyClassTo);if(_el.length)_el.addClass(opts.selectedClass);}}
this.element.trigger(this.widgetEventPrefix+"select",n);},_enableDropAndDrag:function(_node){var self=this;$(_node).children(".dna-treeview-node-content").draggable({revert:'invalid',greedy:false,iframeFix:true,helper:'clone',opacity:0.8});$(_node).droppable({accept:".dna-treeview-node-content",greedy:true,drop:function(event,ui){var _srcNode=ui.draggable.parent();var _srcParent=_srcNode.parent().parent();if(_node==_srcNode[0])return false;if(_srcNode.children("ul").length){if(_srcNode.children("ul").children("li").index($(this))>-1)
return false;}
var _holder=$(">ul",this);if(_holder.length==0){_holder=$("<ul/>");$(this).append(_holder);self._initNodeHolder($(this));$(_node).treenode('refresh');}
_holder.append(_srcNode);_srcNode.treenode('refresh');if(!_srcParent.find("li").length){_srcParent.children("ul").remove();}
if(_srcNode.siblings().length)_srcNode.siblings().treenode('refresh');if($(this).siblings().length)$(this).siblings().treenode('refresh');_srcParent.treenode('refresh');if(_srcParent.find(".dna-treeview-node").length)_srcParent.find(".dna-treeview-node").treenode("refresh");if(_srcParent.siblings().length)_srcParent.siblings().treenode('refresh');var _pos=0;var _children=$(this).find(".dna-treeview-node");if(_children.length)
_pos=_children.index(_srcNode);self.element.trigger(self.widgetEventPrefix+"dropped",{node:_srcNode,parentNode:$(this),position:_pos});}});},selectNode:function(key,value){var n=this.findNodeElement(key,value);if(n)
n.treenode("select");},selectNodeByKey:function(value){var n=this.findNodeElementByKey(value)
if(n)
n.treenode('select');},findNodeElement:function(key,value){return this.element.find("li["+key+"="+value+"]");},findNodeElementByKey:function(value){return this.findNodeElement("key",value);},_initNodes:function(_nodes){var self=this;if(_nodes){if(_nodes.length){_nodes.treenode({tree:self,baseImageUrl:self.options.baseImageUrl,select:function(event,ui){self.element.trigger(self.widgetEventPrefix+"select",ui);}});if(this.options.enableDropAndDrag){_nodes.each(function(i,n){self._enableDropAndDrag(n);});}}}},_initNodeHolder:function(_parent){var _holders=$(_parent).find("ul");if(_holders.length){_holders.addClass("ui-helper-reset").css({"padding-left":"5px","margin-left":"20px"});}},add:function(nodes){if(nodes){if(nodes.length){var _ns=$(nodes);if(_ns.get(0).tagName=="UL"){_ns=$(nodes).children();this.element.append(_ns);this._initNodes(_ns);this._initNodeHolder(_ns);this.element.find("li").treenode("refresh");}}}},destroy:function(){$.Widget.prototype.destroy.call(this);}});$.widget("ui.watermark",{options:{waterMark:null,waterMarkClass:""},_create:function(){var self=this,opts=this.options,el=this.element;self._setWaterMark();el.bind("focus",function(){self._removeWaterMark();});el.bind("blur",function(){self._setWaterMark();});var _form=el.parents("form");if(_form.length){_form.submit(function(){self._removeWaterMark();});}},_setWaterMark:function(){var opts=this.options,el=this.element;if(opts.waterMark){if(el.val()==""){if(opts.waterMarkClass)
el.addClass(opts.waterMarkClass);el.val(opts.waterMark);}}},_removeWaterMark:function(){var opts=this.options,el=this.element;if(opts.waterMark){if(el.val()==opts.waterMark){if(opts.waterMarkClass)
el.removeClass(opts.waterMarkClass);el.val("");}}},destroy:function(){this.element.unbind();$.Widget.prototype.destroy.call(this);}});})(jQuery);fileSharingService=function(){}
fileSharingService.prototype={personalDir:null,publicDir:null,openFolderDialog:function(strUrl,strPath,fCallback){var _dlg=$("<div></div>").appendTo("body").attr("title","Select file dialog"),_treeview=$("<div></div>").appendTo(_dlg);_treeview.treeview({url:strUrl+"?url="+strPath,select:function(event,node){window.dialogResult=node.element.attr("path");}});_dlg.dialog({modal:true,show:"slide",hide:"slide",width:527,position:["left","top"],buttons:{"OK":function(){if($.isFunction(fCallback))
fCallback(window.dialogResult);window.dialogResult=undefined;$(this).dialog("close");$(this).remove();},"Cancel":function(){$(this).dialog("close");}},close:function(){$(this).dialog("destroy");$(this).remove();}});},openFileDialog:function(strUrl,fCallback){var _dlg=$("<div></div>").appendTo("body").attr("title","Select file dialog"),_dlgTable=$("<table style='width:100%;'><tr><td valign='top' id='_fDlgTreeCell' style='width:30%;'></td><td valign='top' id='_fDlgFilesCell'></td></tr></table>").appendTo(_dlg),_treeview=$("<ul/>").appendTo($("#_fDlgTreeCell")),_listContent=$("<div/>").appendTo($("#_fDlgFilesCell"));var _fn=function(_t){var _list=$(">div",_t);_list.bind("listviewitemClick",function(event,ui){window.dialogResult=urlHelper.decode(ui.value);});};var _reload=function(_url){uiHelper.blockUI(_listContent);$.ajax({type:"FLIST",url:_url,success:function(response){uiHelper.unblockUI(_listContent);if(response){_listContent.html(response);_fn(_listContent);}}});}
_reload(strUrl);var _paths=strUrl.split("/");_treeview.css({"min-height":"290px","padding-left":"0px"});_treeview.treeview({url:strUrl,httpMethod:"PLIST",selectedClass:"ui-node-text-selected",});var jdlg=_dlg.dialog({modal:true,show:"slide",hide:"slide",width:650,height:400,buttons:{"Cancel":function(){$(this).dialog("close");},"OK":function(){if($.isFunction(fCallback))
fCallback(window.dialogResult);window.dialogResult=undefined;$(this).dialog("close");$(this).remove();}},close:function(){$(this).dialog("destroy");$(this).remove();}});var btnUpload=$("<button/>").appendTo($(".ui-dialog-buttonpane",jdlg.dialog('widget'))).css({"float":"left"}).button({label:"Upload"});var _selNode=_treeview.treeview("option","selectedNode");var _dlgUploader=new AjaxUpload(btnUpload,{action:_selNode==undefined?strUrl:_selNode.element.attr("rel"),name:"PostedFile",onChange:function(){uiHelper.blockUI();},onComplete:function(file,response){uiHelper.unblockUI();if(response=="OK"){_selNode=_treeview.treeview("option","selectedNode");_reload(_selNode==undefined?strUrl:_selNode.element.attr("rel"));}
else{uiHelper.showMsg(portal.res.Error,response);}}});_treeview.bind("treeviewselect",function(event,node){_dlgUploader._settings.action=node.element.attr("rel");_reload(node.element.attr("rel"));});}}
dynamicUIService=function(){}
dynamicUIService.prototype={showWidgetExplorer:function(explorerUrl,importUrl){var self=this,_settings=$("#dna_page_settings");var hasWidgetZones=false;if(this.zones){if(this.zones.length)
hasWidgetZones=true;}
if(hasWidgetZones){var _defaultZone=$(self.zones[0]);if(_settings.length==0){_settings=$("<div></div>").prependTo("body").css({height:0,"border-top":"none","padding":"5px"}).addClass("ui-widget-content").attr("id","dna_page_settings");_settings.animate({height:221},1000,function(){if(_settings.children().length==0){uiHelper.blockUI(_settings);$.ajax({url:explorerUrl,error:function(response){uiHelper.unblockUI(_settings);_settings.html(response.responseText);},success:function(htm){uiHelper.unblockUI(_settings);_settings.html(htm);var _bar=$("<div></div>").appendTo(_settings).addClass("ui-corner-bottom ui-widget-header").css({"height":"35px","padding":"5px","border-top":"none"}),_closeButton=$("<button/>").appendTo(_bar).click(function(event){event.preventDefault();_settings.animate({height:0},1000,function(){_settings.css({display:"none"});});}).button({label:"Close",icons:{primary:"ui-icon ui-icon-carat-1-n"}});$("<button id='widgetImportButton' />").appendTo(_bar).css({"margin-left":"5px"}).button({label:"Import",icons:{primary:"ui-icon ui-icon-seek-next"}});new AjaxUpload("widgetImportButton",{action:importUrl,name:"importedFile",responseType:"json",data:{"url":document.URL,"zoneID":_defaultZone.attr("id"),pos:0},onSubmit:function(file,extension){uiHelper.blockUI(_settings);},onComplete:function(file,response){uiHelper.unblockUI(_settings);if(response){$nw=$("<div></div>");_defaultZone.prepend($nw);$nw.portlet(response);}}});}});}});}
else
_settings.css({"display":"block"}).animate({height:221},1000);}}}
portalApplication=function(){this.initialize();}
portalApplication.prototype={initialize:function(){this.fileSharing=new fileSharingService();this.dynamicUI=new dynamicUIService();$.ajaxSetup({error:this.error});},res:{timeOut:"The ajax call is time out.The remove server is not response.",unknowError:"There is an unknow error dilling the ajax call."},error:function(XHR,textStatus,errorThrown){var _title=XHR.statusText+"-"+XHR.status;if(textStatus){if(textStatus=="timeout")
uiHelper.showMsg("Ajax Error",portal.res.timeOut);if(textStatus=="error"){var $err=$(XHR.responseText);var $errHeader=$(">h1",$err);var $formatError=$("<div></div>").addClass("ui-state-error ui-corner-all").css({"padding-left":"5px","padding-right":"5px"});if($errHeader.length>0)
$("<p></p>").appendTo($formatError).append($("<span/>").addClass("ui-icon ui-icon-alert").css({"float":"left","margin-right":"5px"})).end().append($("<strong/>").text($errHeader.text()));var $errBody=$(">h2",$err);if($errBody.length>0)
$formatError.append("<p>"+$errBody.text()+"</p>");var htm=$("<div><div>");htm.append($formatError);uiHelper.showMsg(_title,htm.html());}}}}
$(function(){if(!window.portal)window.portal=new portalApplication();window.urlHelper={encode:function(string){return escape(this._utf8_encode(string));},decode:function(string){return this._utf8_decode(unescape(string));},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c);}
else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}
else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}
return utftext;},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++;}
else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}
else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return string;}}
window.uiHelper={htmlEncode:function(strHtml){if(strHtml)
return strHtml.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');else
return"";},htmlDecode:function(strHtml){if(this.isHtmlEncode(strHtml))
return strHtml.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');return strHtml;},addBookMark:function(title){var url=location.href;if($.browser.mozilla){window.sidebar.addPanel(title,url,'');return false;}else if($.browser.msie){window.external.AddFavorite(url,title);return false;}else{alert('Please use CTRL + D to bookmark this website.');}},isHtmlEncode:function(strHtml){if(strHtml.search(/&amp;/g)!=-1||strHtml.search(/&lt;/g)!=-1||strHtml.search(/&gt;/g)!=-1)
return true;else
return false;},previewBox:function(title,src){var img=$('<img alt="'+title+'"style="display:none;padding: 8px;" />').attr('src',src).appendTo('body');uiHelper.blockUI();img.load(function(){uiHelper.unblockUI();var _dlg=img.dialog({title:title,width:img.width(),height:img.height(),modal:true,close:function(){img.remove();}});img.dialog("widget").css({"text-align":"center"});});},createDefaultLoader:function(){var _loader=$("<div></div>").appendTo(document.body).addClass("ui-widget-content ui-corner-all ui-state-active").css({padding:10,height:40,width:150});$("<div>Loading...</div>").appendTo(_loader).css({"text-align":"center","display":"block","margin-bottom":"5px"});var pgbar=$("<div></div>").appendTo(_loader).css({height:10});if($.fn.progressbar){pgbar.progressbar();var iid=setInterval(function(){if(pgbar){var _v=pgbar.progressbar("option",'value');if(_v==100)
pgbar.progressbar("option","value",0);else
pgbar.progressbar("option","value",_v+10);}
else
clearInterval(iid);},1000);}
return _loader;},blockUI:function(el,loader){var _loader=null;if(el){if($(el).length==0)
return;if($(".ui-blocking:first",el).length>0)
return;}
else{if(this.blocker)
return;}
if(loader){if($.isFunction(loader))
_loader=loader();else
_loader=loader;}else
_loader=this.createDefaultLoader();var $el=null;var _w=document.documentElement.scrollWidth,_h=document.documentElement.scrollHeight,_l=0,_t=0;if(el){_w=$(el).outerWidth(true);_h=$(el).outerHeight(true);$el=$('<div></div>').appendTo(el).addClass('ui-blocking').css({width:_w,height:_h});var _pos=$(el).position();_l=_pos.left;_t=_pos.top;}
else{$el=$('<div></div>').appendTo(document.body).addClass('ui-blocking').css({width:_w,height:_h});document.body.style.overflow="hidden";}
$el.append($("<div></div>").addClass("ui-widget-overlay").css({width:_w,height:_h,left:_l,top:_t,"position":"absolute"}));_loader.appendTo($el);var _top=($el.outerHeight(true)/2)-(_loader.outerHeight(true)/2);var _left=($el.outerWidth(true)/2)-(_loader.outerWidth(true)/2);if($.browser.safari)
_left=($el.width()/2)-(_loader.width()/2);if(el){_top=_t+_top;_left=_l+_left;}
_loader.css({left:_left,top:_top,position:"absolute","-moz-opacity":"1","filter":"Alpha(Opacity=100)"});if(el==undefined)
this.blocker=$el;},unblockUI:function(el){if(el){var _blocker=$(".ui-blocking:first",el);if(_blocker.length>0){_blocker.fadeOut("normal");_blocker.remove();}}else{if(this.blocker){this.blocker.fadeOut("normal");this.blocker.remove();this.blocker=null;document.body.style.overflow="";}}},rgbToHex:function(str){str=str.replace(/rgb\(|\)/g,"").split(",");str[0]=parseInt(str[0],10).toString(16).toLowerCase();str[1]=parseInt(str[1],10).toString(16).toLowerCase();str[2]=parseInt(str[2],10).toString(16).toLowerCase();str[0]=(str[0].length==1)?'0'+str[0]:str[0];str[1]=(str[1].length==1)?'0'+str[1]:str[1];str[2]=(str[2].length==1)?'0'+str[2]:str[2];return('#'+str.join(""));},inputDialog:function(strTitle,strInputText,fCallback){var _dlg=$("<div></div>").appendTo("body").attr("title",strTitle);$("<div></div>").appendTo(_dlg).text(strInputText);$("<div></div>").appendTo(_dlg).append("<input />");var _input=$("input",_dlg);if($.ui.textbox)_input.textbox({value:""});_dlg.dialog({bgiframe:true,show:"slide",hide:"slide",resizable:false,modal:true,buttons:{"OK":function(){if(_input.val()){if($.isFunction(fCallback))
fCallback(_input.val());$(this).dialog("close");}
else
_input.focus();},"Cancel":function(){$(this).dialog("close");}}});},confirm:function(title,msg,callback){var _d=$("<div title='"+title+"'><p><span class=\"ui-icon ui-icon-alert\" style=\"float:left; margin:0 7px 20px 0;\"></span>"+msg+"</p></div>");_d.dialog({show:"slide",hide:"slide",modal:true,resizable:false,buttons:{"Yes":function(){if(callback)
callback();_d.dialog("close");_d.remove();},"No":function(){_d.dialog("close");_d.remove();}}});},showMsg:function(title,msg){var _d=$("<div title='"+title+"'>"+msg+"</div>");_d.dialog({show:"slide",hide:"slide",modal:true,overlay:{backgroundColor:'#000000',opacity:0.5},buttons:{"OK":function(){_d.dialog("close");_d.remove();}}});},showDlg:function(title,msg){this.showMsg(title,msg);}}});